Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit e7c3eb6

Browse files
committed
fix ci
1 parent 923882d commit e7c3eb6

28 files changed

+864
-192
lines changed

engine/cli/command_line_parser.cc

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include "commands/engine_install_cmd.h"
88
#include "commands/engine_list_cmd.h"
99
#include "commands/engine_uninstall_cmd.h"
10+
#include "commands/engine_update_cmd.h"
11+
#include "commands/engine_use_cmd.h"
1012
#include "commands/model_del_cmd.h"
1113
#include "commands/model_get_cmd.h"
1214
#include "commands/model_import_cmd.h"
@@ -340,7 +342,7 @@ void CommandLineParser::SetupEngineCommands() {
340342
for (auto& engine : engine_service_.kSupportEngines) {
341343
std::string engine_name{engine};
342344
EngineInstall(install_cmd, engine_name, cml_data_.engine_version,
343-
cml_data_.engine_src);
345+
cml_data_.engine_src, cml_data_.show_menu);
344346
}
345347

346348
auto uninstall_cmd =
@@ -361,6 +363,41 @@ void CommandLineParser::SetupEngineCommands() {
361363
EngineUninstall(uninstall_cmd, engine_name);
362364
}
363365

366+
auto engine_upd_cmd = engines_cmd->add_subcommand("update", "Update engine");
367+
engine_upd_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
368+
" engines update [engine_name]");
369+
engine_upd_cmd->callback([this, engine_upd_cmd] {
370+
if (std::exchange(executed_, true))
371+
return;
372+
if (engine_upd_cmd->get_subcommands().empty()) {
373+
CLI_LOG("[engine_name] is required\n");
374+
CLI_LOG(engine_upd_cmd->help());
375+
}
376+
});
377+
engine_upd_cmd->group(kSubcommands);
378+
for (auto& engine : engine_service_.kSupportEngines) {
379+
std::string engine_name{engine};
380+
EngineUpdate(engine_upd_cmd, engine_name);
381+
}
382+
383+
auto engine_use_cmd =
384+
engines_cmd->add_subcommand("use", "Set engine as default");
385+
engine_use_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
386+
" engines use [engine_name]");
387+
engine_use_cmd->callback([this, engine_use_cmd] {
388+
if (std::exchange(executed_, true))
389+
return;
390+
if (engine_use_cmd->get_subcommands().empty()) {
391+
CLI_LOG("[engine_name] is required\n");
392+
CLI_LOG(engine_use_cmd->help());
393+
}
394+
});
395+
engine_use_cmd->group(kSubcommands);
396+
for (auto& engine : engine_service_.kSupportEngines) {
397+
std::string engine_name{engine};
398+
EngineUse(engine_use_cmd, engine_name);
399+
}
400+
364401
EngineGet(engines_cmd);
365402
}
366403

@@ -428,7 +465,8 @@ void CommandLineParser::SetupSystemCommands() {
428465

429466
void CommandLineParser::EngineInstall(CLI::App* parent,
430467
const std::string& engine_name,
431-
std::string& version, std::string& src) {
468+
std::string& version, std::string& src,
469+
bool show_menu) {
432470
auto install_engine_cmd = parent->add_subcommand(engine_name, "");
433471
install_engine_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
434472
" engines install " + engine_name + " [options]");
@@ -440,13 +478,16 @@ void CommandLineParser::EngineInstall(CLI::App* parent,
440478
install_engine_cmd->add_option("-s, --source", src,
441479
"Install engine by local path");
442480

443-
install_engine_cmd->callback([this, engine_name, &version, &src] {
481+
install_engine_cmd->add_option("-m, --menu", show_menu,
482+
"Display menu for engine variant selection");
483+
484+
install_engine_cmd->callback([this, engine_name, &version, &src, show_menu] {
444485
if (std::exchange(executed_, true))
445486
return;
446487
try {
447-
commands::EngineInstallCmd(download_service_,
448-
cml_data_.config.apiServerHost,
449-
std::stoi(cml_data_.config.apiServerPort))
488+
commands::EngineInstallCmd(
489+
download_service_, cml_data_.config.apiServerHost,
490+
std::stoi(cml_data_.config.apiServerPort), show_menu)
450491
.Exec(engine_name, version, src);
451492
} catch (const std::exception& e) {
452493
CTL_ERR(e.what());
@@ -474,6 +515,47 @@ void CommandLineParser::EngineUninstall(CLI::App* parent,
474515
});
475516
}
476517

518+
void CommandLineParser::EngineUpdate(CLI::App* parent,
519+
const std::string& engine_name) {
520+
auto engine_update_cmd = parent->add_subcommand(engine_name, "");
521+
engine_update_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
522+
" engines update " + engine_name);
523+
engine_update_cmd->group(kEngineGroup);
524+
525+
engine_update_cmd->callback([this, engine_name] {
526+
if (std::exchange(executed_, true))
527+
return;
528+
try {
529+
commands::EngineUpdateCmd().Exec(
530+
cml_data_.config.apiServerHost,
531+
std::stoi(cml_data_.config.apiServerPort), engine_name);
532+
} catch (const std::exception& e) {
533+
CTL_ERR(e.what());
534+
}
535+
});
536+
}
537+
538+
void CommandLineParser::EngineUse(CLI::App* parent,
539+
const std::string& engine_name) {
540+
auto engine_use_cmd = parent->add_subcommand(engine_name, "");
541+
engine_use_cmd->usage("Usage:\n" + commands::GetCortexBinary() +
542+
" engines use " + engine_name);
543+
engine_use_cmd->group(kEngineGroup);
544+
545+
engine_use_cmd->callback([this, engine_name] {
546+
if (std::exchange(executed_, true))
547+
return;
548+
auto result = commands::EngineUseCmd().Exec(
549+
cml_data_.config.apiServerHost,
550+
std::stoi(cml_data_.config.apiServerPort), engine_name);
551+
if (result.has_error()) {
552+
CTL_ERR(result.error());
553+
} else {
554+
CTL_INF("Engine " << engine_name << " is set as default");
555+
}
556+
});
557+
}
558+
477559
void CommandLineParser::EngineGet(CLI::App* parent) {
478560
auto get_cmd = parent->add_subcommand("get", "Get engine info");
479561
get_cmd->usage("Usage:\n" + commands::GetCortexBinary() +

engine/cli/command_line_parser.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,16 @@ class CommandLineParser {
2323
void SetupSystemCommands();
2424

2525
void EngineInstall(CLI::App* parent, const std::string& engine_name,
26-
std::string& version, std::string& src);
26+
std::string& version, std::string& src, bool show_menu);
2727

2828
void EngineUninstall(CLI::App* parent, const std::string& engine_name);
2929

30+
void EngineUpdate(CLI::App* parent, const std::string& engine_name);
31+
3032
void EngineGet(CLI::App* parent);
33+
34+
void EngineUse(CLI::App* parent, const std::string& engine_name);
35+
3136
void ModelUpdate(CLI::App* parent);
3237

3338
CLI::App app_;
@@ -50,6 +55,7 @@ class CommandLineParser {
5055
bool display_engine = false;
5156
bool display_version = false;
5257
std::string filter = "";
58+
bool show_menu = false;
5359

5460
int port;
5561
config_yaml_utils::CortexConfig config;

engine/cli/commands/engine_get_cmd.cc

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#include <json/reader.h>
33
#include <json/value.h>
44
#include <iostream>
5-
6-
#include "httplib.h"
75
#include "server_start_cmd.h"
6+
#include "services/engine_service.h"
7+
#include "utils/curl_utils.h"
88
#include "utils/logging_utils.h"
9+
#include "utils/url_parser.h"
910

1011
// clang-format off
1112
#include <tabulate/table.hpp>
@@ -25,30 +26,36 @@ void EngineGetCmd::Exec(const std::string& host, int port,
2526
}
2627

2728
tabulate::Table table;
28-
table.add_row({"Name", "Supported Formats", "Version", "Variant", "Status"});
29-
httplib::Client cli(host + ":" + std::to_string(port));
30-
auto res = cli.Get("/v1/engines/" + engine_name);
31-
if (res) {
32-
if (res->status == httplib::StatusCode::OK_200) {
33-
Json::Value v;
34-
Json::Reader reader;
35-
reader.parse(res->body, v);
36-
37-
table.add_row({v["name"].asString(), v["format"].asString(),
38-
v["version"].asString(), v["variant"].asString(),
39-
v["status"].asString()});
40-
41-
} else {
42-
CLI_LOG_ERROR(
43-
"Failed to get engine list with status code: " << res->status);
44-
return;
45-
}
46-
} else {
47-
auto err = res.error();
48-
CLI_LOG_ERROR("HTTP error: " << httplib::to_string(err));
29+
table.add_row({"#", "Name", "Version", "Variant", "Status"});
30+
31+
auto url = url_parser::Url{
32+
.protocol = "http",
33+
.host = host + ":" + std::to_string(port),
34+
.pathParams = {"v1", "engines", engine_name},
35+
};
36+
auto result = curl_utils::SimpleGetJson(url.ToFullPath());
37+
if (result.has_error()) {
38+
CTL_ERR(result.error());
4939
return;
5040
}
5141

42+
std::vector<EngineVariantResponse> output;
43+
auto installed_variants = result.value();
44+
for (const auto& variant : installed_variants) {
45+
output.push_back(EngineVariantResponse{
46+
.name = variant["name"].asString(),
47+
.version = variant["version"].asString(),
48+
.engine = engine_name,
49+
});
50+
}
51+
52+
int count = 0;
53+
for (auto const& v : output) {
54+
count += 1;
55+
table.add_row(
56+
{std::to_string(count), v.engine, v.version, v.name, "Installed"});
57+
}
58+
5259
std::cout << table << std::endl;
5360
}
5461
}; // namespace commands

0 commit comments

Comments
 (0)