diff options
| author | Stefan Boberg <[email protected]> | 2023-03-30 15:31:46 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2023-03-30 15:53:16 +0200 |
| commit | bd3bb822f9c2876393bd61b3c3ccc9bb73221694 (patch) | |
| tree | f5d4d2dd29a80308fdca28e6e6d6cbd9d89d8cff | |
| parent | minor: FormatResponse -> FormatHttpResponse (diff) | |
| download | zen-bd3bb822f9c2876393bd61b3c3ccc9bb73221694.tar.xz zen-bd3bb822f9c2876393bd61b3c3ccc9bb73221694.zip | |
zen: sorted commands to reduce potential for merge conflicts
| -rw-r--r-- | zen/zen.cpp | 91 |
1 files changed, 37 insertions, 54 deletions
diff --git a/zen/zen.cpp b/zen/zen.cpp index a085af2c0..3dc10a99b 100644 --- a/zen/zen.cpp +++ b/zen/zen.cpp @@ -40,38 +40,18 @@ ZEN_THIRD_PARTY_INCLUDES_END # include <mimalloc-new-delete.h> #endif -////////////////////////////////////////////////////////////////////////// - -class TemplateCommand : public ZenCmdBase -{ -public: - TemplateCommand() { m_Options.add_options()("r,root", "Root directory for CAS pool", cxxopts::value<std::string>(m_RootDirectory)); } - - virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override - { - ZEN_UNUSED(GlobalOptions, argc, argv); - return 0; - } - - virtual cxxopts::Options& Options() override { return m_Options; } - -private: - cxxopts::Options m_Options{"template", "EDIT THIS COMMAND DESCRIPTION"}; - std::string m_RootDirectory; -}; - -////////////////////////////////////////////////////////////////////////// - bool ZenCmdBase::ParseOptions(int argc, char** argv) { cxxopts::Options& CmdOptions = Options(); cxxopts::ParseResult Result = CmdOptions.parse(argc, argv); + if (Result.count("help")) { printf("%s\n", CmdOptions.help().c_str()); return false; } + if (!Result.unmatched().empty()) { zen::ExtendableStringBuilder<64> StringBuilder; @@ -86,6 +66,7 @@ ZenCmdBase::ParseOptions(int argc, char** argv) StringBuilder.Append('"'); First = false; } + throw cxxopts::OptionParseException(fmt::format("Invalid arguments: {}", StringBuilder.ToView())); } @@ -132,6 +113,7 @@ ZenCmdBase::FormatHttpResponse(const cpr::Response& Response) { return std::string(ResponseString); } + return fmt::format("{}: {}", ResponseString, Content); } @@ -204,30 +186,30 @@ main(int argc, char** argv) auto _ = zen::MakeGuard([] { spdlog::shutdown(); }); - HashCommand HashCmd; + CacheInfoCommand CacheInfoCmd; CopyCommand CopyCmd; + CreateOplogCommand CreateOplogCmd; + CreateProjectCommand CreateProjectCmd; DedupCommand DedupCmd; - DropCommand DropCmd; - StatusCommand StatusCmd; - TopCommand TopCmd; - PrintCommand PrintCmd; - PrintPackageCommand PrintPkgCmd; - PsCommand PsCmd; - UpCommand UpCmd; DownCommand DownCmd; - ExportOplogCommand ExportOplogCmd; - ImportOplogCommand ImportOplogCmd; - VersionCommand VersionCmd; - CacheInfoCommand CacheInfoCmd; + DropCommand DropCmd; DropProjectCommand ProjectDropCmd; - ProjectInfoCommand ProjectInfoCmd; - CreateProjectCommand CreateProjectCmd; - CreateOplogCommand CreateOplogCmd; + ExportOplogCommand ExportOplogCmd; GcCommand GcCmd; GcStatusCommand GcStatusCmd; + HashCommand HashCmd; + ImportOplogCommand ImportOplogCmd; + PrintCommand PrintCmd; + PrintPackageCommand PrintPkgCmd; + ProjectInfoCommand ProjectInfoCmd; + PsCommand PsCmd; RpcReplayCommand RpcReplayCmd; RpcStartRecordingCommand RpcStartRecordingCmd; RpcStopRecordingCommand RpcStopRecordingCmd; + StatusCommand StatusCmd; + TopCommand TopCmd; + UpCommand UpCmd; + VersionCommand VersionCmd; #if ZEN_WITH_TESTS RunTestsCommand RunTestsCmd; @@ -241,30 +223,30 @@ main(int argc, char** argv) } Commands[] = { // clang-format off // {"chunk", &ChunkCmd, "Perform chunking"}, + {"cache-info", &CacheInfoCmd, "Info on cache, namespace or bucket"}, {"copy", &CopyCmd, "Copy file(s)"}, {"dedup", &DedupCmd, "Dedup files"}, + {"down", &DownCmd, "Bring zen server down"}, {"drop", &DropCmd, "Drop cache namespace or bucket"}, + {"gc-status", &GcStatusCmd, "Garbage collect zen storage status check"}, + {"gc", &GcCmd, "Garbage collect zen storage"}, {"hash", &HashCmd, "Compute file hashes"}, + {"oplog-create", &CreateOplogCmd, "Create a project oplog"}, + {"oplog-export", &ExportOplogCmd, "Export project store oplog"}, + {"oplog-import", &ImportOplogCmd, "Import project store oplog"}, {"print", &PrintCmd, "Print compact binary object"}, {"printpackage", &PrintPkgCmd, "Print compact binary package"}, - {"status", &StatusCmd, "Show zen status"}, - {"ps", &PsCmd, "Enumerate running zen server instances"}, - {"top", &TopCmd, "Monitor zen server activity"}, - {"up", &UpCmd, "Bring zen server up"}, - {"down", &DownCmd, "Bring zen server down"}, - {"version", &VersionCmd, "Get zen server version"}, - {"cache-info", &CacheInfoCmd, "Info on cache, namespace or bucket"}, + {"project-create", &CreateProjectCmd, "Create a project"}, {"project-drop", &ProjectDropCmd, "Drop project or project oplog"}, {"project-info", &ProjectInfoCmd, "Info on project or project oplog"}, - {"project-create", &CreateProjectCmd, "Create a project"}, - {"oplog-create", &CreateOplogCmd, "Create a project oplog"}, - {"oplog-export", &ExportOplogCmd, "Export project store oplog"}, - {"oplog-import", &ImportOplogCmd, "Import project store oplog"}, - {"gc", &GcCmd, "Garbage collect zen storage"}, - {"gc-status", &GcStatusCmd, "Garbage collect zen storage status check"}, + {"ps", &PsCmd, "Enumerate running zen server instances"}, + {"rpc-record-replay", &RpcReplayCmd, "Stops recording of cache rpc requests on a host"}, {"rpc-record-start", &RpcStartRecordingCmd, "Replays a previously recorded session of rpc requests"}, {"rpc-record-stop", &RpcStopRecordingCmd, "Starts recording of cache rpc requests on a host"}, - {"rpc-record-replay", &RpcReplayCmd, "Stops recording of cache rpc requests on a host"}, + {"status", &StatusCmd, "Show zen status"}, + {"top", &TopCmd, "Monitor zen server activity"}, + {"up", &UpCmd, "Bring zen server up"}, + {"version", &VersionCmd, "Get zen server version"}, #if ZEN_WITH_TESTS {"runtests", &RunTestsCmd, "Run zen tests"}, #endif @@ -354,9 +336,10 @@ main(int argc, char** argv) std::string SubCommand = "<None>"; cxxopts::Options Options("zen", "Zen management tool"); - Options.add_options()("d, debug", "Enable debugging", cxxopts::value<bool>(GlobalOptions.IsDebug)); + + Options.add_options()("d, debug", "Enable debugging", cxxopts::value<bool>(GlobalOptions.IsDebug)); Options.add_options()("v, verbose", "Enable verbose logging", cxxopts::value<bool>(GlobalOptions.IsVerbose)); - Options.add_options()("help", "Show command line help"); + Options.add_options()("help", "Show command line help"); Options.add_options()("c, command", "Sub command", cxxopts::value<std::string>(SubCommand)); Options.parse_positional({"command"}); @@ -414,7 +397,7 @@ main(int argc, char** argv) { std::string HelpMessage = Options.help(); - printf("Error parsing snapshot program arguments: %s\n\n%s", Ex.what(), HelpMessage.c_str()); + printf("Error parsing program arguments: %s\n\n%s", Ex.what(), HelpMessage.c_str()); return 9; } |