Settings: Fix cli-switches not overriding .json config

pull/239/head
Peter Repukat 1 year ago
parent cf23edafdb
commit e6db328273

@ -219,13 +219,14 @@ namespace Settings {
inline void Parse(const std::vector<std::wstring>& args) inline void Parse(const std::vector<std::wstring>& args)
{ {
std::wstring configName; std::wstring configName;
std::vector<std::function<void()>> cli_overrides;
for (const auto& arg : args) { for (const auto& arg : args) {
if (arg.empty()) { if (arg.empty()) {
continue; continue;
} }
if (cmd_args.contains(arg)) if (cmd_args.contains(arg))
{ {
cmd_args.at(arg)(); cli_overrides.push_back(cmd_args.at(arg));
} }
else { else {
configName += L" " + std::wstring(arg.begin(), arg.end()); configName += L" " + std::wstring(arg.begin(), arg.end());
@ -254,12 +255,18 @@ namespace Settings {
if (!json_file.is_open()) { if (!json_file.is_open()) {
spdlog::error(L"Couldn't open settings file {}", path.wstring()); spdlog::error(L"Couldn't open settings file {}", path.wstring());
spdlog::debug(L"Using sane defaults..."); spdlog::debug(L"Using sane defaults...");
for (const auto& ovr : cli_overrides) {
ovr();
}
return; return;
} }
settings_path_ = path; settings_path_ = path;
const auto& json = nlohmann::json::parse(json_file); const auto& json = nlohmann::json::parse(json_file);
Parse(json); Parse(json);
for (const auto& ovr : cli_overrides) {
ovr();
}
spdlog::debug("Read config file \"{}\"; config: {}", path.string(), json.dump()); spdlog::debug("Read config file \"{}\"; config: {}", path.string(), json.dump());
json_file.close(); json_file.close();
} }

Loading…
Cancel
Save