aboutsummaryrefslogtreecommitdiff
path: root/src/zen/zen.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-11-15 15:46:00 +0100
committerGitHub <[email protected]>2023-11-15 15:46:00 +0100
commit9db70b8b27df7690b061d0a002b5a67b84c474cf (patch)
treea7c5c0e5952ffe40a0be390203aa97b50618755a /src/zen/zen.cpp
parentUpdate README.md (diff)
downloadarchived-zen-9db70b8b27df7690b061d0a002b5a67b84c474cf.tar.xz
archived-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/zen/zen.cpp')
-rw-r--r--src/zen/zen.cpp42
1 files changed, 21 insertions, 21 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();