From 9db70b8b27df7690b061d0a002b5a67b84c474cf Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Wed, 15 Nov 2023 15:46:00 +0100 Subject: remove dependency on cxxopts exception types (#542) changed options parsing so that we don't depend on cxxopts exception types this makes it possible to use any cxxopts-version including beyond 3.0.0 --- src/zenserver/config.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/zenserver/config.cpp') diff --git a/src/zenserver/config.cpp b/src/zenserver/config.cpp index 08ba6dc95..e7edd5745 100644 --- a/src/zenserver/config.cpp +++ b/src/zenserver/config.cpp @@ -1337,9 +1337,18 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) try { - auto result = options.parse(argc, argv); + cxxopts::ParseResult Result; - if (result.count("help")) + try + { + Result = options.parse(argc, argv); + } + catch (std::exception& Ex) + { + throw zen::OptionParseException(Ex.what()); + } + + if (Result.count("help")) { ZEN_CONSOLE("{}", options.help()); #if ZEN_PLATFORM_WINDOWS @@ -1373,21 +1382,15 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions) if (!ServerOptions.ConfigFile.empty()) { - ParseConfigFile(ServerOptions.ConfigFile, ServerOptions, result, OutputConfigFile); + ParseConfigFile(ServerOptions.ConfigFile, ServerOptions, Result, OutputConfigFile); } else { - ParseConfigFile(ServerOptions.DataDir / "zen_cfg.lua", ServerOptions, result, OutputConfigFile); + ParseConfigFile(ServerOptions.DataDir / "zen_cfg.lua", ServerOptions, Result, OutputConfigFile); } ValidateOptions(ServerOptions); } - catch (cxxopts::OptionParseException& e) - { - ZEN_CONSOLE_ERROR("Error parsing zenserver arguments: {}\n\n{}", e.what(), options.help()); - - throw; - } catch (zen::OptionParseException& e) { ZEN_CONSOLE_ERROR("Error parsing zenserver arguments: {}\n\n{}", e.what(), options.help()); -- cgit v1.2.3