Skip to content

Commit

Permalink
fix: CLI engine use
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
namchuai committed Nov 28, 2024
1 parent 7dd43fb commit f3e32a3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions engine/cli/commands/engine_use_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,29 @@ cpp::result<void, std::string> EngineUseCmd::Exec(const std::string& host,
return cpp::fail("Invalid variant selection");
}

auto selected_version = cli_selection_utils::PrintSelection(
variant_map[selected_variant.value()]);
if (!selected_variant.has_value()) {
std::optional<std::string> selected_version = std::nullopt;
if (variant_map[selected_variant.value()].size() == 1) {
selected_version = variant_map[selected_variant.value()][0];
} else {
selected_version = cli_selection_utils::PrintSelection(
variant_map[selected_variant.value()]);
}
if (!selected_version.has_value()) {
CTL_ERR("Invalid version selection");
return cpp::fail("Invalid version selection");
}

Json::Value body;
body["variant"] = selected_variant.value();
body["version"] = selected_version.value();
auto set_default_engine_variant = url_parser::Url{
.protocol = "http",
.host = host + ":" + std::to_string(port),
.pathParams = {"v1", "engines", engine, "default"},
};

auto response =
curl_utils::SimplePostJson(set_default_engine_variant.ToFullPath());
auto response = curl_utils::SimplePostJson(
set_default_engine_variant.ToFullPath(), body.toStyledString());
if (response.has_error()) {
CTL_ERR(response.error());
return cpp::fail("Failed to set default engine variant");
Expand Down

0 comments on commit f3e32a3

Please sign in to comment.