summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 17:38:22 +0100
committerThorbjørn Lindeijer <bjorn@lindeijer.nl>2024-03-02 17:38:25 +0100
commita25d857ed0bebc2c3e1473d06bea89286941886c (patch)
tree99c8069acb1b2c756951d3047d73db4cf1b6b4b4 /src/main.cpp
parent72ceaaa426166bfa425f519c2418a66872839e12 (diff)
downloadmana-a25d857ed0bebc2c3e1473d06bea89286941886c.tar.gz
mana-a25d857ed0bebc2c3e1473d06bea89286941886c.tar.bz2
mana-a25d857ed0bebc2c3e1473d06bea89286941886c.tar.xz
mana-a25d857ed0bebc2c3e1473d06bea89286941886c.zip
Exit with error when invalid server type is passed on CLI
Also made it exit with error when there is an unknown option or missing argument.
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 6244b946..b44f4d3a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -118,6 +118,8 @@ static void parseOptions(int argc, char *argv[], Client::Options &options)
break;
case '?': // Unknown option
case ':': // Missing argument
+ options.exitWithError = true;
+ [[fallthrough]];
case 'h':
options.printHelp = true;
break;
@@ -158,7 +160,12 @@ static void parseOptions(int argc, char *argv[], Client::Options &options)
options.screenshotDir = optarg;
break;
case 'y':
- options.serverType = optarg;
+ options.serverType = ServerInfo::parseType(optarg);
+ if (options.serverType == ServerType::UNKNOWN)
+ {
+ std::cerr << _("Invalid server type, expected one of: tmwathena, manaserv") << std::endl;
+ options.exitWithError = true;
+ }
break;
}
}
@@ -203,16 +210,14 @@ int main(int argc, char *argv[])
Client::Options options;
parseOptions(argc, argv, options);
+ if (options.printVersion)
+ printVersion();
+
if (options.printHelp)
- {
printHelp();
- return 0;
- }
- else if (options.printVersion)
- {
- printVersion();
- return 0;
- }
+
+ if (options.printHelp || options.printVersion || options.exitWithError)
+ return options.exitWithError ? 1 : 0;
initInternationalization();