diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-02 17:38:22 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-03-02 17:38:25 +0100 |
commit | a25d857ed0bebc2c3e1473d06bea89286941886c (patch) | |
tree | 99c8069acb1b2c756951d3047d73db4cf1b6b4b4 /src/main.cpp | |
parent | 72ceaaa426166bfa425f519c2418a66872839e12 (diff) | |
download | mana-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.cpp | 23 |
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(); |