From c1fc13210c252fb758fd38aab3593b4d3be0f7e0 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 9 Sep 2024 09:42:50 +0700 Subject: [PATCH] [#1088] Update engine install/uninstall CLI commands According to discussion, engine install and uninstall should be: cortex engines install cortex engines uninstall --- engine/controllers/command_line_parser.cc | 38 +++++++++++++---------- engine/controllers/command_line_parser.h | 6 ++-- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index b8ad72f58..0c8f3e26e 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -16,7 +16,6 @@ #include "config/yaml_config.h" #include "httplib.h" #include "services/engine_service.h" -#include "utils/cortex_utils.h" #include "utils/file_manager_utils.h" #include "utils/logging_utils.h" @@ -135,9 +134,19 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { command.Exec(); }); + auto install_cmd = engines_cmd->add_subcommand("install", "Install engine"); + install_cmd->callback([] { CLI_LOG("Engine name can't be empty!"); }); for (auto& engine : engine_service_.kSupportEngines) { std::string engine_name{engine}; - EngineManagement(engines_cmd, engine_name, version); + EngineInstall(install_cmd, engine_name, version); + } + + auto uninstall_cmd = + engines_cmd->add_subcommand("uninstall", "Uninstall engine"); + uninstall_cmd->callback([] { CLI_LOG("Engine name can't be empty!"); }); + for (auto& engine : engine_service_.kSupportEngines) { + std::string engine_name{engine}; + EngineUninstall(uninstall_cmd, engine_name); } EngineGet(engines_cmd); @@ -227,25 +236,22 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { return true; } -void CommandLineParser::EngineManagement(CLI::App* parent, - const std::string& engine_name, - std::string& version) { - auto engine_cmd = - parent->add_subcommand(engine_name, "Manage " + engine_name + " engine"); +void CommandLineParser::EngineInstall(CLI::App* parent, + const std::string& engine_name, + std::string& version) { + auto install_engine_cmd = parent->add_subcommand(engine_name, ""); - auto install_cmd = engine_cmd->add_subcommand( - "install", "Install " + engine_name + " engine"); - install_cmd->add_option("-v, --version", version, - "Engine version. Default will be latest"); - - install_cmd->callback([engine_name, &version] { + install_engine_cmd->callback([&] { commands::EngineInitCmd eic(engine_name, version); eic.Exec(); }); +} + +void CommandLineParser::EngineUninstall(CLI::App* parent, + const std::string& engine_name) { + auto uninstall_engine_cmd = parent->add_subcommand(engine_name, ""); - auto uninstall_desc{"Uninstall " + engine_name + " engine"}; - auto uninstall_cmd = engine_cmd->add_subcommand("uninstall", uninstall_desc); - uninstall_cmd->callback([engine_name] { + uninstall_engine_cmd->callback([&] { commands::EngineUninstallCmd cmd(engine_name); cmd.Exec(); }); diff --git a/engine/controllers/command_line_parser.h b/engine/controllers/command_line_parser.h index 0fa89e241..e4a2f47c5 100644 --- a/engine/controllers/command_line_parser.h +++ b/engine/controllers/command_line_parser.h @@ -9,8 +9,10 @@ class CommandLineParser { bool SetupCommand(int argc, char** argv); private: - void EngineManagement(CLI::App* parent, const std::string& engine_name, - std::string& version); + void EngineInstall(CLI::App* parent, const std::string& engine_name, + std::string& version); + + void EngineUninstall(CLI::App* parent, const std::string& engine_name); void EngineGet(CLI::App* parent);