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

Commit a5152b0

Browse files
committed
chore: add -DCORTEX_CONFIG_FILE_NAME
1 parent 703368b commit a5152b0

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

engine/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ if(DEBUG)
5959
add_compile_definitions(ALLOW_ALL_CORS)
6060
endif()
6161

62+
if(NOT DEFINED CORTEX_CONFIG_FILE_PATH)
63+
set(CORTEX_CONFIG_FILE_PATH "user_home")
64+
endif()
65+
6266
if(NOT DEFINED CORTEX_CPP_VERSION)
6367
set(CORTEX_CPP_VERSION "default_version")
6468
endif()
@@ -80,6 +84,7 @@ if(DEFINED CMAKE_JS_INC)
8084
endif()
8185

8286
add_compile_definitions(CORTEX_CPP_VERSION="${CORTEX_CPP_VERSION}")
87+
add_compile_definitions(CORTEX_CONFIG_FILE_PATH="${CORTEX_CONFIG_FILE_PATH}")
8388

8489
option(CMAKE_BUILD_TEST "Enable testing" OFF)
8590
if(CMAKE_BUILD_TEST)
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#pragma once
2-
#include <array>
2+
33
#include <string>
44

55
namespace commands {
@@ -11,8 +11,5 @@ class EngineUninstallCmd {
1111

1212
private:
1313
std::string engine_;
14-
15-
static constexpr std::array<const char*, 3> supportedEngines_ = {
16-
"cortex.llamacpp", "cortex.onnx", "cortex.tensorrt-llm"};
1714
};
1815
} // namespace commands

engine/controllers/command_line_parser.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
#include "utils/cortex_utils.h"
1818
#include "utils/logging_utils.h"
1919

20-
CommandLineParser::CommandLineParser() : app_("Cortex.cpp CLI") {}
20+
CommandLineParser::CommandLineParser()
21+
: app_("Cortex.cpp CLI"), engine_service_{EngineService()} {}
2122

2223
bool CommandLineParser::SetupCommand(int argc, char** argv) {
2324
std::string model_id;
@@ -127,9 +128,10 @@ bool CommandLineParser::SetupCommand(int argc, char** argv) {
127128
command.Exec();
128129
});
129130

130-
EngineManagement(engines_cmd, "cortex.llamacpp", version);
131-
EngineManagement(engines_cmd, "cortex.onnx", version);
132-
EngineManagement(engines_cmd, "cortex.tensorrt-llm", version);
131+
for (auto& engine : engine_service_.kSupportEngines) {
132+
std::string engine_name{engine};
133+
EngineManagement(engines_cmd, engine_name, version);
134+
}
133135

134136
EngineGet(engines_cmd);
135137
}
@@ -186,9 +188,8 @@ void CommandLineParser::EngineManagement(CLI::App* parent,
186188

187189
void CommandLineParser::EngineGet(CLI::App* parent) {
188190
auto get_cmd = parent->add_subcommand("get", "Get an engine info");
189-
auto engine_service = EngineService();
190191

191-
for (auto& engine : engine_service.kSupportEngines) {
192+
for (auto& engine : engine_service_.kSupportEngines) {
192193
std::string engine_name{engine};
193194
std::string desc = "Get " + engine_name + " status";
194195

engine/controllers/command_line_parser.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "CLI/CLI.hpp"
4+
#include "services/engine_service.h"
45

56
class CommandLineParser {
67
public:
@@ -14,4 +15,5 @@ class CommandLineParser {
1415
void EngineGet(CLI::App* parent);
1516

1617
CLI::App app_;
18+
EngineService engine_service_;
1719
};

engine/utils/config_yaml_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ inline void CreateConfigFileIfNotExist() {
5454
.port = kDefaultPort,
5555
};
5656
std::cout << "config: " << config.dataFolderPath << "\n";
57-
DumpYamlConfig(config, config_path);
57+
DumpYamlConfig(config, config_path.string());
5858
}
5959

6060
inline CortexConfig FromYaml(const std::string& path,

engine/utils/file_manager_utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
namespace file_manager_utils {
1717
constexpr std::string_view kCortexConfigurationFileName = ".cortexrc";
18+
constexpr std::string_view kDefaultConfigurationPath = "user_home";
1819

1920
inline std::filesystem::path GetExecutableFolderContainerPath() {
2021
#if defined(__APPLE__) && defined(__MACH__)
@@ -73,6 +74,11 @@ inline std::filesystem::path GetHomeDirectoryPath() {
7374
}
7475

7576
inline std::filesystem::path GetConfigurationPath() {
77+
std::string config_file_path{CORTEX_CONFIG_FILE_PATH};
78+
79+
if (config_file_path != kDefaultConfigurationPath) {
80+
return std::filesystem::path(config_file_path);
81+
}
7682
auto home_path = GetHomeDirectoryPath();
7783
auto configuration_path = home_path / kCortexConfigurationFileName;
7884
return configuration_path;

0 commit comments

Comments
 (0)