|
1 | 1 | #include "command_line_parser.h" |
2 | 2 | #include <memory> |
3 | 3 | #include <optional> |
| 4 | +#include <string> |
4 | 5 | #include "commands/cortex_upd_cmd.h" |
5 | 6 | #include "commands/engine_get_cmd.h" |
6 | 7 | #include "commands/engine_install_cmd.h" |
7 | 8 | #include "commands/engine_list_cmd.h" |
| 9 | +#include "commands/engine_release_cmd.h" |
8 | 10 | #include "commands/engine_uninstall_cmd.h" |
9 | | -#include "commands/model_alias_cmd.h" |
10 | 11 | #include "commands/model_del_cmd.h" |
11 | 12 | #include "commands/model_get_cmd.h" |
12 | 13 | #include "commands/model_import_cmd.h" |
@@ -94,8 +95,8 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) { |
94 | 95 | CLI_LOG("\nNew Cortex release available: " |
95 | 96 | << CORTEX_CPP_VERSION << " -> " << *latest_version); |
96 | 97 | CLI_LOG("To update, run: " << commands::GetRole() |
97 | | - << commands::GetCortexBinary() |
98 | | - << " update"); |
| 98 | + << commands::GetCortexBinary() |
| 99 | + << " update"); |
99 | 100 | } |
100 | 101 | done = true; |
101 | 102 | }); |
@@ -138,7 +139,8 @@ void CommandLineParser::SetupCommonCommands() { |
138 | 139 | } |
139 | 140 | }); |
140 | 141 |
|
141 | | - auto run_cmd = app_.add_subcommand("run", "Shortcut: pull, start & chat with a model"); |
| 142 | + auto run_cmd = |
| 143 | + app_.add_subcommand("run", "Shortcut: pull, start & chat with a model"); |
142 | 144 | run_cmd->group(kCommonCommandsGroup); |
143 | 145 | run_cmd->usage("Usage:\n" + commands::GetCortexBinary() + |
144 | 146 | " run [options] [model_id]"); |
@@ -270,30 +272,6 @@ void CommandLineParser::SetupModelCommands() { |
270 | 272 | cml_data_.model_id); |
271 | 273 | }); |
272 | 274 |
|
273 | | - std::string model_alias; |
274 | | - auto model_alias_cmd = |
275 | | - models_cmd->add_subcommand("alias", "Add a model alias instead of ID"); |
276 | | - model_alias_cmd->usage("Usage:\n" + commands::GetCortexBinary() + |
277 | | - " models alias --model_id [model_id] --alias [alias]"); |
278 | | - model_alias_cmd->group(kSubcommands); |
279 | | - model_alias_cmd->add_option( |
280 | | - "--model_id", cml_data_.model_id, |
281 | | - "Can be a model ID or model alias"); |
282 | | - model_alias_cmd->add_option("--alias", cml_data_.model_alias, |
283 | | - "new alias to be set"); |
284 | | - model_alias_cmd->callback([this, model_alias_cmd]() { |
285 | | - if (std::exchange(executed_, true)) |
286 | | - return; |
287 | | - if (cml_data_.model_id.empty() || cml_data_.model_alias.empty()) { |
288 | | - CLI_LOG("[model_id] and [alias] are required\n"); |
289 | | - CLI_LOG(model_alias_cmd->help()); |
290 | | - return; |
291 | | - } |
292 | | - commands::ModelAliasCmd mdc; |
293 | | - mdc.Exec(cml_data_.config.apiServerHost, |
294 | | - std::stoi(cml_data_.config.apiServerPort), cml_data_.model_id, |
295 | | - cml_data_.model_alias); |
296 | | - }); |
297 | 275 | // Model update parameters comment |
298 | 276 | ModelUpdate(models_cmd); |
299 | 277 |
|
@@ -348,6 +326,21 @@ void CommandLineParser::SetupEngineCommands() { |
348 | 326 | std::stoi(cml_data_.config.apiServerPort)); |
349 | 327 | }); |
350 | 328 |
|
| 329 | + auto installv2_cmd = engines_cmd->add_subcommand("release", "Install engine"); |
| 330 | + installv2_cmd->group(kSubcommands); |
| 331 | + installv2_cmd->callback([this, installv2_cmd] { |
| 332 | + if (std::exchange(executed_, true)) |
| 333 | + return; |
| 334 | + if (installv2_cmd->get_subcommands().empty()) { |
| 335 | + CLI_LOG("[engine_name] is required\n"); |
| 336 | + CLI_LOG(installv2_cmd->help()); |
| 337 | + } |
| 338 | + }); |
| 339 | + for (auto& engine : engine_service_.kSupportEngines) { |
| 340 | + std::string engine_name{engine}; |
| 341 | + EngineInstallV2(installv2_cmd, engine_name); |
| 342 | + } |
| 343 | + |
351 | 344 | auto install_cmd = engines_cmd->add_subcommand("install", "Install engine"); |
352 | 345 | install_cmd->usage("Usage:\n" + commands::GetCortexBinary() + |
353 | 346 | " engines install [engine_name] [options]"); |
@@ -417,8 +410,7 @@ void CommandLineParser::SetupSystemCommands() { |
417 | 410 | ssc.Exec(); |
418 | 411 | }); |
419 | 412 |
|
420 | | - auto ps_cmd = |
421 | | - app_.add_subcommand("ps", "Show active model statuses"); |
| 413 | + auto ps_cmd = app_.add_subcommand("ps", "Show active model statuses"); |
422 | 414 | ps_cmd->group(kSystemGroup); |
423 | 415 | ps_cmd->usage("Usage:\n" + commands::GetCortexBinary() + "ps"); |
424 | 416 | ps_cmd->callback([&]() { |
@@ -446,6 +438,25 @@ void CommandLineParser::SetupSystemCommands() { |
446 | 438 | }); |
447 | 439 | } |
448 | 440 |
|
| 441 | +void CommandLineParser::EngineInstallV2(CLI::App* parent, |
| 442 | + const std::string& engine_name) { |
| 443 | + auto install_engine_cmd = parent->add_subcommand(engine_name, ""); |
| 444 | + install_engine_cmd->usage("Usage:\n" + commands::GetCortexBinary() + |
| 445 | + " engines install " + engine_name + " [options]"); |
| 446 | + install_engine_cmd->group(kEngineGroup); |
| 447 | + install_engine_cmd->callback([this, engine_name] { |
| 448 | + if (std::exchange(executed_, true)) |
| 449 | + return; |
| 450 | + auto result = commands::EngineReleaseCmd().Exec( |
| 451 | + cml_data_.config.apiServerHost, |
| 452 | + std::stoi(cml_data_.config.apiServerPort), engine_name); |
| 453 | + |
| 454 | + if (result.has_error()) { |
| 455 | + CLI_LOG(result.error()); |
| 456 | + } |
| 457 | + }); |
| 458 | +} |
| 459 | + |
449 | 460 | void CommandLineParser::EngineInstall(CLI::App* parent, |
450 | 461 | const std::string& engine_name, |
451 | 462 | std::string& version, std::string& src) { |
|
0 commit comments