@@ -282,7 +282,10 @@ class ArgsManagerHelper {
282
282
* options that are not normally boolean (e.g. using -nodebuglogfile to request
283
283
* that debug log output is not sent to any file at all).
284
284
*/
285
- static void InterpretOption (std::string key, std::string val, std::map<std::string, std::vector<std::string>>& args)
285
+
286
+ NODISCARD static bool InterpretOption (std::string key, std::string val, unsigned int flags,
287
+ std::map<std::string, std::vector<std::string>>& args,
288
+ std::string& error)
286
289
{
287
290
assert (key[0 ] == ' -' );
288
291
@@ -293,18 +296,22 @@ static void InterpretOption(std::string key, std::string val, std::map<std::stri
293
296
++option_index;
294
297
}
295
298
if (key.substr (option_index, 2 ) == " no" ) {
296
- const bool bool_val = InterpretBool (val);
297
299
key.erase (option_index, 2 );
298
- if (!bool_val ) {
300
+ if (flags & ArgsManager::ALLOW_BOOL) {
301
+ if (InterpretBool (val)) {
302
+ args[key].clear ();
303
+ return true ;
304
+ }
299
305
// Double negatives like -nofoo=0 are supported (but discouraged)
300
306
LogPrintf (" Warning: parsed potentially confusing double-negative %s=%s\n " , key, val);
301
307
val = " 1" ;
302
308
} else {
303
- args[ key]. clear ( );
304
- return ;
309
+ error = strprintf ( " Negating of %s is meaningless and therefore forbidden " , key. c_str () );
310
+ return false ;
305
311
}
306
312
}
307
313
args[key].push_back (val);
314
+ return true ;
308
315
}
309
316
310
317
ArgsManager::ArgsManager ()
@@ -395,7 +402,9 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
395
402
396
403
const unsigned int flags = FlagsOfKnownArg (key);
397
404
if (flags) {
398
- InterpretOption (key, val, m_override_args);
405
+ if (!InterpretOption (key, val, flags, m_override_args, error)) {
406
+ return false ;
407
+ }
399
408
} else {
400
409
error = strprintf (" Invalid parameter %s" , key.c_str ());
401
410
return false ;
@@ -839,7 +848,9 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file
839
848
const std::string strKey = std::string (" -" ) + option.first ;
840
849
const unsigned int flags = FlagsOfKnownArg (strKey);
841
850
if (flags) {
842
- InterpretOption (strKey, option.second , m_config_args);
851
+ if (!InterpretOption (strKey, option.second , flags, m_config_args, error)) {
852
+ return false ;
853
+ }
843
854
} else {
844
855
if (ignore_invalid_keys) {
845
856
LogPrintf (" Ignoring unknown configuration value %s\n " , option.first );
0 commit comments