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

Commit 8d50506

Browse files
committed
chore: consolidate download service
1 parent 93bce74 commit 8d50506

23 files changed

+160
-111
lines changed

engine/commands/cortex_upd_cmd.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
385385
.localPath = local_path,
386386
}}}};
387387

388-
DownloadService().AddDownloadTask(
388+
auto result = DownloadService().AddDownloadTask(
389389
download_task, [](const DownloadTask& finishedTask) {
390390
// try to unzip the downloaded file
391391
CTL_INF("Downloaded engine path: "
@@ -400,6 +400,9 @@ bool CortexUpdCmd::HandleGithubRelease(const nlohmann::json& assets,
400400

401401
CTL_INF("Finished!");
402402
});
403+
if (result.has_error()) {
404+
CTL_ERR("Failed to download: " << result.error());
405+
}
403406
break;
404407
}
405408
}
@@ -447,7 +450,7 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
447450
.localPath = localPath,
448451
}}};
449452

450-
DownloadService().AddDownloadTask(
453+
auto result = DownloadService().AddDownloadTask(
451454
download_task, [](const DownloadTask& finishedTask) {
452455
// try to unzip the downloaded file
453456
CTL_INF("Downloaded engine path: "
@@ -461,6 +464,10 @@ bool CortexUpdCmd::GetNightly(const std::string& v) {
461464

462465
CTL_INF("Finished!");
463466
});
467+
if (result.has_error()) {
468+
CTL_ERR("Failed to download: " << result.error());
469+
return false;
470+
}
464471

465472
// Replace binary file
466473
auto executable_path = file_manager_utils::GetExecutableFolderContainerPath();

engine/commands/engine_get_cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
namespace commands {
66
class EngineGetCmd {
77
public:
8-
explicit EngineGetCmd() : engine_service_{EngineService()} {};
8+
explicit EngineGetCmd()
9+
: engine_service_{EngineService(std::make_shared<DownloadService>())} {};
910

1011
void Exec(const std::string& engineName) const;
1112

engine/commands/engine_install_cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ namespace commands {
77

88
class EngineInstallCmd {
99
public:
10-
explicit EngineInstallCmd() : engine_service_{EngineService()} {};
10+
explicit EngineInstallCmd()
11+
: engine_service_{EngineService(std::make_shared<DownloadService>())} {};
1112

1213
void Exec(const std::string& engine, const std::string& version = "latest",
1314
const std::string& src = "");

engine/commands/engine_list_cmd.cc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#include "engine_list_cmd.h"
22
#include <tabulate/table.hpp>
3-
#include "services/engine_service.h"
43

54
namespace commands {
65

76
bool EngineListCmd::Exec() {
8-
auto engine_service = EngineService();
9-
auto status_list = engine_service.GetEngineInfoList();
7+
auto status_list = engine_service_.GetEngineInfoList();
108

119
tabulate::Table table;
1210
table.add_row(

engine/commands/engine_list_cmd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
#pragma once
22

3+
#include "services/engine_service.h"
4+
35
namespace commands {
46
class EngineListCmd {
57
public:
8+
explicit EngineListCmd()
9+
: engine_service_{EngineService(std::make_shared<DownloadService>())} {};
10+
611
bool Exec();
12+
13+
private:
14+
EngineService engine_service_;
715
};
816

917
} // namespace commands

engine/commands/engine_uninstall_cmd.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#pragma once
22

3+
#include <memory>
34
#include <string>
45
#include "services/engine_service.h"
56

67
namespace commands {
78
class EngineUninstallCmd {
89
public:
9-
explicit EngineUninstallCmd() : engine_service_{EngineService()} {};
10+
explicit EngineUninstallCmd()
11+
: engine_service_{EngineService(std::make_shared<DownloadService>())} {};
1012

1113
void Exec(const std::string& engine);
1214

engine/commands/model_del_cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ namespace commands {
77

88
class ModelDelCmd {
99
public:
10-
explicit ModelDelCmd() : model_service_{ModelService()} {};
10+
explicit ModelDelCmd()
11+
: model_service_{ModelService(std::make_shared<DownloadService>())} {};
1112

1213
void Exec(const std::string& model_handle);
1314

engine/commands/model_pull_cmd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ namespace commands {
66

77
class ModelPullCmd {
88
public:
9-
explicit ModelPullCmd() : model_service_{ModelService()} {};
9+
explicit ModelPullCmd()
10+
: model_service_{ModelService(std::make_shared<DownloadService>())} {};
1011
void Exec(const std::string& input);
1112

1213
private:

engine/commands/run_cmd.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
2+
23
#include <string>
3-
#include "nlohmann/json.hpp"
44
#include "services/engine_service.h"
55
#include "services/model_service.h"
66

@@ -11,7 +11,8 @@ class RunCmd {
1111
: host_{std::move(host)},
1212
port_{port},
1313
model_handle_{std::move(model_handle)},
14-
model_service_{ModelService()} {};
14+
engine_service_{EngineService(std::make_shared<DownloadService>())},
15+
model_service_{ModelService(std::make_shared<DownloadService>())} {};
1516

1617
void Exec(bool chat_flag);
1718

engine/controllers/command_line_parser.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "command_line_parser.h"
2+
#include <memory>
23
#include "commands/chat_cmd.h"
34
#include "commands/chat_completion_cmd.h"
45
#include "commands/cmd_info.h"
@@ -34,7 +35,8 @@ constexpr const auto kSystemGroup = "System";
3435
constexpr const auto kSubcommands = "Subcommands";
3536
} // namespace
3637
CommandLineParser::CommandLineParser()
37-
: app_("Cortex.cpp CLI"), engine_service_{EngineService()} {}
38+
: app_("Cortex.cpp CLI"),
39+
engine_service_{EngineService(std::make_shared<DownloadService>())} {}
3840

3941
bool CommandLineParser::SetupCommand(int argc, char** argv) {
4042
app_.usage("Usage:\n" + commands::GetCortexBinary() +

0 commit comments

Comments
 (0)