diff --git a/src/util/system.cpp b/src/util/system.cpp --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -296,21 +296,23 @@ * This method also tracks when the -no form was supplied, and if so, checks * whether there was a double-negative (-nofoo=0 -> -foo=1). * - * If there was not a double negative, it removes the "no" from the key, and - * returns true, indicating the caller should clear the args vector to indicate - * a negated option. + * If there was not a double negative, it removes the "no" from the key + * and clears the args vector to indicate a negated option. * - * If there was a double negative, it removes "no" from the key, sets the value - * to "1" and returns false. + * If there was a double negative, it removes "no" from the key, sets the + * value to "1" and pushes the key and the updated value to the args vector. * - * If there was no "no", it leaves key and value untouched and returns false. + * If there was no "no", it leaves key and value untouched and pushes them + * to the args vector. * * Where an option was negated can be later checked using the IsArgNegated() * method. One use case for this is to have a way to disable options that are * not normally boolean (e.g. using -nodebuglogfile to request that debug log * output is not sent to any file at all). */ -static bool InterpretNegatedOption(std::string &key, std::string &val) { +static void +InterpretOption(std::string key, std::string val, + std::map> &args) { assert(key[0] == '-'); size_t option_index = key.find('.'); @@ -320,7 +322,7 @@ ++option_index; } if (key.substr(option_index, 2) == "no") { - bool bool_val = InterpretBool(val); + const bool bool_val = InterpretBool(val); key.erase(option_index, 2); if (!bool_val) { // Double negatives like -nofoo=0 are supported (but discouraged) @@ -329,10 +331,11 @@ key, val); val = "1"; } else { - return true; + args[key].clear(); + return; } } - return false; + args[key].push_back(val); } ArgsManager::ArgsManager() @@ -455,12 +458,7 @@ } } - // Check for -nofoo - if (InterpretNegatedOption(key, val)) { - m_override_args[key].clear(); - } else { - m_override_args[key].push_back(val); - } + InterpretOption(key, val, m_override_args); } // we do not allow -includeconf from command line, so we clear it here @@ -966,7 +964,7 @@ return false; } for (const std::pair &option : options) { - std::string strKey = std::string("-") + option.first; + const std::string strKey = std::string("-") + option.first; // Check that the arg is known if (!IsArgKnown(strKey)) { if (!ignore_invalid_keys) { @@ -980,12 +978,7 @@ } } - std::string strValue = option.second; - if (InterpretNegatedOption(strKey, strValue)) { - m_config_args[strKey].clear(); - } else { - m_config_args[strKey].push_back(strValue); - } + InterpretOption(strKey, option.second, m_config_args); } return true; }