diff options
| author | Stefan Boberg <[email protected]> | 2025-10-10 16:22:41 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2025-10-10 16:22:41 +0200 |
| commit | b7e2506638f482f11b24873676ec2ede92f2ed3a (patch) | |
| tree | 39dd37a4cb7a32f8f791d4baa84cf8a8779ed323 | |
| parent | limit cores in temp test code (diff) | |
| download | zen-sb/zen-master.tar.xz zen-sb/zen-master.zip | |
temp stuffsb/zen-master
| -rw-r--r-- | src/zen/cmds/master_cmd.cpp | 60 | ||||
| -rw-r--r-- | src/zen/cmds/master_cmd.h | 2 |
2 files changed, 54 insertions, 8 deletions
diff --git a/src/zen/cmds/master_cmd.cpp b/src/zen/cmds/master_cmd.cpp index c882a1eab..cd3da9fcf 100644 --- a/src/zen/cmds/master_cmd.cpp +++ b/src/zen/cmds/master_cmd.cpp @@ -34,6 +34,52 @@ public: private: }; +class StartCommand : public MasterCommand::SubCommand +{ +public: + StartCommand() : MasterCommand::SubCommand("start"sv) {} + + virtual void Run(MasterCommand::MasterConfig& Config, int argc, char* argv[]) override + { + ZEN_UNUSED(argc, argv); + HttpClient Http(Config.m_HostName); + + if (HttpClient::Response Result = Http.Get("/admin/info"sv, HttpClient::Accept(ZenContentType::kYAML))) + { + ZEN_CONSOLE("{}", Result.ToText()); + } + else + { + Result.ThrowError(fmt::format("Failed getting info from '{}' ('{}')"sv, Config.m_HostName, Result.ErrorMessage("error: "))); + } + } + +private: +}; + +class StopCommand : public MasterCommand::SubCommand +{ +public: + StopCommand() : MasterCommand::SubCommand("stop"sv) {} + + virtual void Run(MasterCommand::MasterConfig& Config, int argc, char* argv[]) override + { + ZEN_UNUSED(argc, argv); + HttpClient Http(Config.m_HostName); + + if (HttpClient::Response Result = Http.Get("/admin/info"sv, HttpClient::Accept(ZenContentType::kYAML))) + { + ZEN_CONSOLE("{}", Result.ToText()); + } + else + { + Result.ThrowError(fmt::format("Failed getting info from '{}' ('{}')"sv, Config.m_HostName, Result.ErrorMessage("error: "))); + } + } + +private: +}; + } // namespace zen::master namespace zen { @@ -64,12 +110,10 @@ MasterCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) ZEN_UNUSED(GlobalOptions); master::StatusCommand StatusCmd; + master::StartCommand StartCmd; + master::StopCommand StopCmd; - struct SubCommandEntry - { - std::string_view Name; - SubCommand& Command; - } SubCommands[] = {{"status"sv, StatusCmd}}; + SubCommand* SubCommands[] = {&StatusCmd, &StartCmd, &StopCmd}; SubCommand* Cmd = nullptr; @@ -77,11 +121,11 @@ MasterCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) for (int i = 1; i < argc; ++i) { - for (const auto& SubCmd : SubCommands) + for (SubCommand* SubCmd : SubCommands) { - if (argv[i] == SubCmd.Name) + if (argv[i] == SubCmd->Name()) { - Cmd = &SubCmd.Command; + Cmd = SubCmd; ParentArgCount = i; goto parsed; diff --git a/src/zen/cmds/master_cmd.h b/src/zen/cmds/master_cmd.h index 78e433e2c..83e907eeb 100644 --- a/src/zen/cmds/master_cmd.h +++ b/src/zen/cmds/master_cmd.h @@ -31,6 +31,8 @@ public: virtual void Run(MasterConfig& Config, int argc, char* argv[]) = 0; + inline const std::string_view Name() const { return m_CommandName; } + private: std::string m_CommandName; cxxopts::Options m_Options; |