|
9 | 9 | #include "commands/engine_get_cmd.h" |
10 | 10 | #include "commands/engine_install_cmd.h" |
11 | 11 | #include "commands/engine_list_cmd.h" |
| 12 | +#include "commands/engine_load_cmd.h" |
12 | 13 | #include "commands/engine_uninstall_cmd.h" |
| 14 | +#include "commands/engine_unload_cmd.h" |
13 | 15 | #include "commands/engine_update_cmd.h" |
14 | 16 | #include "commands/engine_use_cmd.h" |
15 | 17 | #include "commands/hardware_activate_cmd.h" |
@@ -474,6 +476,41 @@ void CommandLineParser::SetupEngineCommands() { |
474 | 476 | EngineUse(engine_use_cmd, engine_name); |
475 | 477 | } |
476 | 478 |
|
| 479 | + auto engine_load_cmd = engines_cmd->add_subcommand("load", "Load engine"); |
| 480 | + engine_load_cmd->usage("Usage:\n" + commands::GetCortexBinary() + |
| 481 | + " engines load [engine_name]"); |
| 482 | + engine_load_cmd->callback([this, engine_load_cmd] { |
| 483 | + if (std::exchange(executed_, true)) |
| 484 | + return; |
| 485 | + if (engine_load_cmd->get_subcommands().empty()) { |
| 486 | + CLI_LOG("[engine_name] is required\n"); |
| 487 | + CLI_LOG(engine_load_cmd->help()); |
| 488 | + } |
| 489 | + }); |
| 490 | + engine_load_cmd->group(kSubcommands); |
| 491 | + for (auto& engine : engine_service_.kSupportEngines) { |
| 492 | + std::string engine_name{engine}; |
| 493 | + EngineLoad(engine_load_cmd, engine_name); |
| 494 | + } |
| 495 | + |
| 496 | + auto engine_unload_cmd = |
| 497 | + engines_cmd->add_subcommand("unload", "Unload engine"); |
| 498 | + engine_unload_cmd->usage("Usage:\n" + commands::GetCortexBinary() + |
| 499 | + " engines unload [engine_name]"); |
| 500 | + engine_unload_cmd->callback([this, engine_unload_cmd] { |
| 501 | + if (std::exchange(executed_, true)) |
| 502 | + return; |
| 503 | + if (engine_unload_cmd->get_subcommands().empty()) { |
| 504 | + CLI_LOG("[engine_name] is required\n"); |
| 505 | + CLI_LOG(engine_unload_cmd->help()); |
| 506 | + } |
| 507 | + }); |
| 508 | + engine_unload_cmd->group(kSubcommands); |
| 509 | + for (auto& engine : engine_service_.kSupportEngines) { |
| 510 | + std::string engine_name{engine}; |
| 511 | + EngineUnload(engine_unload_cmd, engine_name); |
| 512 | + } |
| 513 | + |
477 | 514 | EngineGet(engines_cmd); |
478 | 515 | } |
479 | 516 |
|
@@ -691,6 +728,44 @@ void CommandLineParser::EngineUpdate(CLI::App* parent, |
691 | 728 | }); |
692 | 729 | } |
693 | 730 |
|
| 731 | +void CommandLineParser::EngineUnload(CLI::App* parent, |
| 732 | + const std::string& engine_name) { |
| 733 | + auto sub_cmd = parent->add_subcommand(engine_name, ""); |
| 734 | + sub_cmd->usage("Usage:\n" + commands::GetCortexBinary() + " engines unload " + |
| 735 | + engine_name); |
| 736 | + sub_cmd->group(kEngineGroup); |
| 737 | + |
| 738 | + sub_cmd->callback([this, engine_name] { |
| 739 | + if (std::exchange(executed_, true)) |
| 740 | + return; |
| 741 | + auto result = commands::EngineUnloadCmd().Exec( |
| 742 | + cml_data_.config.apiServerHost, |
| 743 | + std::stoi(cml_data_.config.apiServerPort), engine_name); |
| 744 | + if (result.has_error()) { |
| 745 | + CTL_ERR(result.error()); |
| 746 | + } |
| 747 | + }); |
| 748 | +} |
| 749 | + |
| 750 | +void CommandLineParser::EngineLoad(CLI::App* parent, |
| 751 | + const std::string& engine_name) { |
| 752 | + auto sub_cmd = parent->add_subcommand(engine_name, ""); |
| 753 | + sub_cmd->usage("Usage:\n" + commands::GetCortexBinary() + " engines load " + |
| 754 | + engine_name); |
| 755 | + sub_cmd->group(kEngineGroup); |
| 756 | + |
| 757 | + sub_cmd->callback([this, engine_name] { |
| 758 | + if (std::exchange(executed_, true)) |
| 759 | + return; |
| 760 | + auto result = commands::EngineLoadCmd().Exec( |
| 761 | + cml_data_.config.apiServerHost, |
| 762 | + std::stoi(cml_data_.config.apiServerPort), engine_name); |
| 763 | + if (result.has_error()) { |
| 764 | + CTL_ERR(result.error()); |
| 765 | + } |
| 766 | + }); |
| 767 | +} |
| 768 | + |
694 | 769 | void CommandLineParser::EngineUse(CLI::App* parent, |
695 | 770 | const std::string& engine_name) { |
696 | 771 | auto engine_use_cmd = parent->add_subcommand(engine_name, ""); |
|
0 commit comments