@@ -268,22 +268,21 @@ class ArgsManagerHelper {
268
268
* This method also tracks when the -no form was supplied, and if so,
269
269
* checks whether there was a double-negative (-nofoo=0 -> -foo=1).
270
270
*
271
- * If there was not a double negative, it removes the "no" from the key,
272
- * and returns true, indicating the caller should clear the args vector
273
- * to indicate a negated option.
271
+ * If there was not a double negative, it removes the "no" from the key
272
+ * and clears the args vector to indicate a negated option.
274
273
*
275
274
* If there was a double negative, it removes "no" from the key, sets the
276
- * value to "1" and returns false .
275
+ * value to "1" and pushes the key and the updated value to the args vector .
277
276
*
278
- * If there was no "no", it leaves key and value untouched and returns
279
- * false .
277
+ * If there was no "no", it leaves key and value untouched and pushes them
278
+ * to the args vector .
280
279
*
281
280
* Where an option was negated can be later checked using the
282
281
* IsArgNegated() method. One use case for this is to have a way to disable
283
282
* options that are not normally boolean (e.g. using -nodebuglogfile to request
284
283
* that debug log output is not sent to any file at all).
285
284
*/
286
- static bool InterpretNegatedOption (std::string& key, std::string& val)
285
+ static void InterpretOption (std::string key, std::string val, std::map<std::string, std::vector<std::string>>& args )
287
286
{
288
287
assert (key[0 ] == ' -' );
289
288
@@ -294,17 +293,18 @@ static bool InterpretNegatedOption(std::string& key, std::string& val)
294
293
++option_index;
295
294
}
296
295
if (key.substr (option_index, 2 ) == " no" ) {
297
- bool bool_val = InterpretBool (val);
296
+ const bool bool_val = InterpretBool (val);
298
297
key.erase (option_index, 2 );
299
298
if (!bool_val ) {
300
299
// Double negatives like -nofoo=0 are supported (but discouraged)
301
300
LogPrintf (" Warning: parsed potentially confusing double-negative %s=%s\n " , key, val);
302
301
val = " 1" ;
303
302
} else {
304
- return true ;
303
+ args[key].clear ();
304
+ return ;
305
305
}
306
306
}
307
- return false ;
307
+ args[key]. push_back (val) ;
308
308
}
309
309
310
310
ArgsManager::ArgsManager () :
@@ -411,12 +411,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
411
411
}
412
412
}
413
413
414
- // Check for -nofoo
415
- if (InterpretNegatedOption (key, val)) {
416
- m_override_args[key].clear ();
417
- } else {
418
- m_override_args[key].push_back (val);
419
- }
414
+ InterpretOption (key, val, m_override_args);
420
415
}
421
416
422
417
// we do not allow -includeconf from command line, so we clear it here
@@ -845,7 +840,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
845
840
return false ;
846
841
}
847
842
for (const std::pair<std::string, std::string>& option : options) {
848
- std::string strKey = std::string (" -" ) + option.first ;
843
+ const std::string strKey = std::string (" -" ) + option.first ;
849
844
// Check that the arg is known
850
845
if (!IsArgKnown (strKey)) {
851
846
if (!ignore_invalid_keys) {
@@ -857,12 +852,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
857
852
}
858
853
}
859
854
860
- std::string strValue = option.second ;
861
- if (InterpretNegatedOption (strKey, strValue)) {
862
- m_config_args[strKey].clear ();
863
- } else {
864
- m_config_args[strKey].push_back (strValue);
865
- }
855
+ InterpretOption (strKey, option.second , m_config_args);
866
856
}
867
857
return true ;
868
858
}
0 commit comments