Changeset View
Changeset View
Standalone View
Standalone View
src/util/system.cpp
Show First 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | for (int i = 1; i < argc; i++) { | ||||
if (!ParseKeyValue(key, val)) { | if (!ParseKeyValue(key, val)) { | ||||
break; | break; | ||||
} | } | ||||
// Transform -foo to foo | // Transform -foo to foo | ||||
key.erase(0, 1); | key.erase(0, 1); | ||||
std::string section; | std::string section; | ||||
util::SettingsValue value = InterpretOption(section, key, val); | util::SettingsValue value = InterpretOption(section, key, val); | ||||
Optional<unsigned int> flags = GetArgFlags('-' + key); | std::optional<unsigned int> flags = GetArgFlags('-' + key); | ||||
if (flags) { | if (flags) { | ||||
if (!CheckValid(key, value, *flags, error)) { | if (!CheckValid(key, value, *flags, error)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Weird behavior preserved for backwards compatibility: command | // Weird behavior preserved for backwards compatibility: command | ||||
// line options with section prefixes are allowed but ignored. It | // line options with section prefixes are allowed but ignored. It | ||||
// would be better if these options triggered the Invalid parameter | // would be better if these options triggered the Invalid parameter | ||||
// error below. | // error below. | ||||
Show All 15 Lines | if (auto *includes = | ||||
"-includeconf cannot be used from commandline; -includeconf=" + | "-includeconf cannot be used from commandline; -includeconf=" + | ||||
include.get_str() + "\n"; | include.get_str() + "\n"; | ||||
success = false; | success = false; | ||||
} | } | ||||
} | } | ||||
return success; | return success; | ||||
} | } | ||||
Optional<unsigned int> ArgsManager::GetArgFlags(const std::string &name) const { | std::optional<unsigned int> | ||||
ArgsManager::GetArgFlags(const std::string &name) const { | |||||
LOCK(cs_args); | LOCK(cs_args); | ||||
for (const auto &arg_map : m_available_args) { | for (const auto &arg_map : m_available_args) { | ||||
const auto search = arg_map.second.find(name); | const auto search = arg_map.second.find(name); | ||||
if (search != arg_map.second.end()) { | if (search != arg_map.second.end()) { | ||||
return search->second.m_flags; | return search->second.m_flags; | ||||
} | } | ||||
} | } | ||||
return nullopt; | return std::nullopt; | ||||
} | } | ||||
std::vector<std::string> ArgsManager::GetArgs(const std::string &strArg) const { | std::vector<std::string> ArgsManager::GetArgs(const std::string &strArg) const { | ||||
std::vector<std::string> result; | std::vector<std::string> result; | ||||
for (const util::SettingsValue &value : GetSettingsList(strArg)) { | for (const util::SettingsValue &value : GetSettingsList(strArg)) { | ||||
result.push_back( | result.push_back( | ||||
value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str()); | value.isFalse() ? "0" : value.isTrue() ? "1" : value.get_str()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 496 Lines • ▼ Show 20 Lines | if (!GetConfigOptions(stream, filepath, error, options, | ||||
m_config_sections)) { | m_config_sections)) { | ||||
return false; | return false; | ||||
} | } | ||||
for (const std::pair<std::string, std::string> &option : options) { | for (const std::pair<std::string, std::string> &option : options) { | ||||
std::string section; | std::string section; | ||||
std::string key = option.first; | std::string key = option.first; | ||||
util::SettingsValue value = | util::SettingsValue value = | ||||
InterpretOption(section, key, option.second); | InterpretOption(section, key, option.second); | ||||
Optional<unsigned int> flags = GetArgFlags('-' + key); | std::optional<unsigned int> flags = GetArgFlags('-' + key); | ||||
if (flags) { | if (flags) { | ||||
if (!CheckValid(key, value, *flags, error)) { | if (!CheckValid(key, value, *flags, error)) { | ||||
return false; | return false; | ||||
} | } | ||||
m_settings.ro_config[section][key].push_back(value); | m_settings.ro_config[section][key].push_back(value); | ||||
} else { | } else { | ||||
if (ignore_invalid_keys) { | if (ignore_invalid_keys) { | ||||
LogPrintf("Ignoring unknown configuration value %s\n", | LogPrintf("Ignoring unknown configuration value %s\n", | ||||
▲ Show 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void ArgsManager::logArgsPrefix( | void ArgsManager::logArgsPrefix( | ||||
const std::string &prefix, const std::string §ion, | const std::string &prefix, const std::string §ion, | ||||
const std::map<std::string, std::vector<util::SettingsValue>> &args) const { | const std::map<std::string, std::vector<util::SettingsValue>> &args) const { | ||||
std::string section_str = section.empty() ? "" : "[" + section + "] "; | std::string section_str = section.empty() ? "" : "[" + section + "] "; | ||||
for (const auto &arg : args) { | for (const auto &arg : args) { | ||||
for (const auto &value : arg.second) { | for (const auto &value : arg.second) { | ||||
Optional<unsigned int> flags = GetArgFlags('-' + arg.first); | std::optional<unsigned int> flags = GetArgFlags('-' + arg.first); | ||||
if (flags) { | if (flags) { | ||||
std::string value_str = | std::string value_str = | ||||
(*flags & SENSITIVE) ? "****" : value.write(); | (*flags & SENSITIVE) ? "****" : value.write(); | ||||
LogPrintf("%s %s%s=%s\n", prefix, section_str, arg.first, | LogPrintf("%s %s%s=%s\n", prefix, section_str, arg.first, | ||||
value_str); | value_str); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 314 Lines • Show Last 20 Lines |