diff options
| author | Stefan Boberg <[email protected]> | 2023-11-15 15:46:00 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-11-15 15:46:00 +0100 |
| commit | 9db70b8b27df7690b061d0a002b5a67b84c474cf (patch) | |
| tree | a7c5c0e5952ffe40a0be390203aa97b50618755a /src | |
| parent | Update README.md (diff) | |
| download | zen-9db70b8b27df7690b061d0a002b5a67b84c474cf.tar.xz zen-9db70b8b27df7690b061d0a002b5a67b84c474cf.zip | |
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
Diffstat (limited to 'src')
| -rw-r--r-- | src/zen/zen.cpp | 42 | ||||
| -rw-r--r-- | src/zenserver/config.cpp | 23 |
2 files changed, 34 insertions, 31 deletions
diff --git a/src/zen/zen.cpp b/src/zen/zen.cpp index 65a02633a..f9a8d102f 100644 --- a/src/zen/zen.cpp +++ b/src/zen/zen.cpp @@ -51,7 +51,16 @@ bool ZenCmdBase::ParseOptions(int argc, char** argv) { cxxopts::Options& CmdOptions = Options(); - cxxopts::ParseResult Result = CmdOptions.parse(argc, argv); + cxxopts::ParseResult Result; + + try + { + Result = CmdOptions.parse(argc, argv); + } + catch (std::exception& Ex) + { + throw zen::OptionParseException(Ex.what()); + } CmdOptions.show_positional_help(); @@ -248,6 +257,7 @@ main(int argc, char** argv) const char* CmdSummary; } Commands[] = { // clang-format off + {"attach", &AttachCmd, "Add a sponsor process to a running zen service"}, {"bench", &BenchCmd, "Utility command for benchmarking"}, // {"chunk", &ChunkCmd, "Perform chunking"}, {"cache-details", &CacheDetailsCmd, "Details on cache"}, @@ -261,6 +271,8 @@ main(int argc, char** argv) {"gc-status", &GcStatusCmd, "Garbage collect zen storage status check"}, {"gc", &GcCmd, "Garbage collect zen storage"}, {"hash", &HashCmd, "Compute file hashes"}, + {"jobs", &JobCmd, "Show/cancel zen background jobs"}, + {"logs", &LoggingCmd, "Show/control zen logging"}, {"oplog-create", &CreateOplogCmd, "Create a project oplog"}, {"oplog-delete", &DeleteOplogCmd, "Delete a project oplog"}, {"oplog-export", &ExportOplogCmd, "Export project store oplog"}, @@ -282,12 +294,9 @@ main(int argc, char** argv) {"scrub", &ScrubCmd, "Scrub zen storage (verify data integrity)"}, {"serve", &ServeCmd, "Serve files from a directory"}, {"status", &StatusCmd, "Show zen status"}, - {"logs", &LoggingCmd, "Show/control zen logging"}, - {"jobs", &JobCmd, "Show/cancel zen background jobs"}, {"top", &TopCmd, "Monitor zen server activity"}, {"trace", &TraceCmd, "Control zen realtime tracing"}, {"up", &UpCmd, "Bring zen server up"}, - {"attach", &AttachCmd, "Add a sponsor process to a running zen service"}, {"version", &VersionCmd, "Get zen server version"}, {"vfs", &VfsCmd, "Manage virtual file system"}, {"flush", &FlushCmd, "Flush storage"}, @@ -402,9 +411,16 @@ main(int argc, char** argv) printf("available commands:\n"); + std::map<std::string, std::string> SortedCmds; + for (const CommandInfo& CmdInfo : Commands) { - printf(" %-20s %s\n", CmdInfo.CmdName, CmdInfo.CmdSummary); + SortedCmds[CmdInfo.CmdName] = CmdInfo.CmdSummary; + } + + for (const auto& Kv : SortedCmds) + { + printf(" %-20s %s\n", Kv.first.c_str(), Kv.second.c_str()); } exit(0); @@ -429,14 +445,6 @@ main(int argc, char** argv) { return CmdInfo.Cmd->Run(GlobalOptions, (int)CommandArgVec.size(), CommandArgVec.data()); } - catch (cxxopts::OptionParseException& Ex) - { - std::string help = VerbOptions.help(); - - printf("Error parsing arguments for command '%s': %s\n\n%s", SubCommand.c_str(), Ex.what(), help.c_str()); - - exit(11); - } catch (OptionParseException& Ex) { std::string help = VerbOptions.help(); @@ -450,14 +458,6 @@ main(int argc, char** argv) printf("Unknown command specified: '%s', exiting\n", SubCommand.c_str()); } - catch (cxxopts::OptionParseException& Ex) - { - std::string HelpMessage = Options.help(); - - printf("Error parsing program arguments: %s\n\n%s", Ex.what(), HelpMessage.c_str()); - - return 9; - } catch (OptionParseException& Ex) { std::string HelpMessage = Options.help(); 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()); |