Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions engine/utils/config_yaml_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ inline void DumpYamlConfig(const CortexConfig& config,
}

inline CortexConfig FromYaml(const std::string& path,
const std::string& variant) {
const CortexConfig& default_cfg) {
std::filesystem::path config_file_path{path};
if (!std::filesystem::exists(config_file_path)) {
throw std::runtime_error("File not found: " + path);
Expand All @@ -60,11 +60,20 @@ inline CortexConfig FromYaml(const std::string& path,
max_lines = node["maxLogLines"].as<int>();
}
CortexConfig config = {
.logFolderPath = node["logFolderPath"].as<std::string>(),
.dataFolderPath = node["dataFolderPath"].as<std::string>(),
.maxLogLines = max_lines,
.apiServerHost = node["apiServerHost"].as<std::string>(),
.apiServerPort = node["apiServerPort"].as<std::string>(),
.logFolderPath = node["logFolderPath"]
? node["logFolderPath"].as<std::string>()
: default_cfg.logFolderPath,
.dataFolderPath = node["dataFolderPath"]
? node["dataFolderPath"].as<std::string>()
: default_cfg.dataFolderPath,
.maxLogLines = node["maxLogLines"] ? node["maxLogLines"].as<int>()
: default_cfg.maxLogLines,
.apiServerHost = node["apiServerHost"]
? node["apiServerHost"].as<std::string>()
: default_cfg.apiServerHost,
.apiServerPort = node["apiServerPort"]
? node["apiServerPort"].as<std::string>()
: default_cfg.apiServerPort,
};
return config;
} catch (const YAML::BadFile& e) {
Expand Down
32 changes: 24 additions & 8 deletions engine/utils/file_manager_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,7 @@ inline std::filesystem::path GetConfigurationPath() {
return configuration_path;
}

inline void CreateConfigFileIfNotExist() {
auto config_path = GetConfigurationPath();
if (std::filesystem::exists(config_path)) {
// already exists
return;
}
inline std::string GetDefaultDataFolderName() {
#ifndef CORTEX_VARIANT
#define CORTEX_VARIANT "prod"
#endif
Expand All @@ -128,6 +123,17 @@ inline void CreateConfigFileIfNotExist() {
env_postfix.append("-").append(kNightlyVariant);
}
default_data_folder_name.append(env_postfix);
return default_data_folder_name;
}

inline void CreateConfigFileIfNotExist() {
auto config_path = GetConfigurationPath();
if (std::filesystem::exists(config_path)) {
// already exists
return;
}

auto default_data_folder_name = GetDefaultDataFolderName();

CLI_LOG("Config file not found. Creating one at " + config_path.string());
auto defaultDataFolderPath =
Expand All @@ -146,8 +152,18 @@ inline void CreateConfigFileIfNotExist() {

inline config_yaml_utils::CortexConfig GetCortexConfig() {
auto config_path = GetConfigurationPath();
std::string variant = ""; // TODO: empty for now
return config_yaml_utils::FromYaml(config_path.string(), variant);
auto default_data_folder_name = GetDefaultDataFolderName();
auto default_data_folder_path =
file_manager_utils::GetHomeDirectoryPath() / default_data_folder_name;
auto default_cfg = config_yaml_utils::CortexConfig{
.logFolderPath = default_data_folder_path.string(),
.dataFolderPath = default_data_folder_path.string(),
.maxLogLines = config_yaml_utils::kDefaultMaxLines,
.apiServerHost = config_yaml_utils::kDefaultHost,
.apiServerPort = config_yaml_utils::kDefaultPort,
};

return config_yaml_utils::FromYaml(config_path.string(), default_cfg);
}

inline std::filesystem::path GetCortexDataPath() {
Expand Down