@@ -460,6 +460,13 @@ class ArgsManagerHelper {
460
460
public:
461
461
typedef std::map<std::string, std::vector<std::string>> MapArgs;
462
462
463
+ /* * Convert regular argument into the network-specific setting */
464
+ static inline std::string NetworkArg (const ArgsManager& am, const std::string& arg)
465
+ {
466
+ assert (arg.length () > 1 && arg[0 ] == ' -' );
467
+ return " -" + am.m_network + " ." + arg.substr (1 );
468
+ }
469
+
463
470
/* * Find arguments in a map and add them to a vector */
464
471
static inline void AddArgs (std::vector<std::string>& res, const MapArgs& map_args, const std::string& arg)
465
472
{
@@ -507,6 +514,13 @@ class ArgsManagerHelper {
507
514
// But in contrast we return the first argument seen in a config file,
508
515
// so "foo=bar \n foo=baz" in the config file gives
509
516
// GetArg(am,"foo")={true,"bar"}
517
+ if (!am.m_network .empty ()) {
518
+ found_result = GetArgHelper (am.m_config_args , NetworkArg (am, arg));
519
+ if (found_result.first ) {
520
+ return found_result;
521
+ }
522
+ }
523
+
510
524
found_result = GetArgHelper (am.m_config_args , arg);
511
525
if (found_result.first ) {
512
526
return found_result;
@@ -539,9 +553,17 @@ class ArgsManagerHelper {
539
553
*/
540
554
static bool InterpretNegatedOption (std::string& key, std::string& val)
541
555
{
542
- if (key.substr (0 , 3 ) == " -no" ) {
556
+ assert (key[0 ] == ' -' );
557
+
558
+ size_t option_index = key.find (' .' );
559
+ if (option_index == std::string::npos) {
560
+ option_index = 1 ;
561
+ } else {
562
+ ++option_index;
563
+ }
564
+ if (key.substr (option_index, 2 ) == " no" ) {
543
565
bool bool_val = InterpretBool (val);
544
- key.erase (1 , 2 );
566
+ key.erase (option_index , 2 );
545
567
if (!bool_val ) {
546
568
// Double negatives like -nofoo=0 are supported (but discouraged)
547
569
LogPrintf (" Warning: parsed potentially confusing double-negative %s=%s\n " , key, val);
@@ -553,6 +575,11 @@ static bool InterpretNegatedOption(std::string& key, std::string& val)
553
575
return false ;
554
576
}
555
577
578
+ void ArgsManager::SelectConfigNetwork (const std::string& network)
579
+ {
580
+ m_network = network;
581
+ }
582
+
556
583
void ArgsManager::ParseParameters (int argc, const char * const argv[])
557
584
{
558
585
LOCK (cs_args);
@@ -595,6 +622,9 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
595
622
596
623
LOCK (cs_args);
597
624
ArgsManagerHelper::AddArgs (result, m_override_args, strArg);
625
+ if (!m_network.empty ()) {
626
+ ArgsManagerHelper::AddArgs (result, m_config_args, ArgsManagerHelper::NetworkArg (*this , strArg));
627
+ }
598
628
ArgsManagerHelper::AddArgs (result, m_config_args, strArg);
599
629
return result;
600
630
}
@@ -612,6 +642,11 @@ bool ArgsManager::IsArgNegated(const std::string& strArg) const
612
642
const auto & ov = m_override_args.find (strArg);
613
643
if (ov != m_override_args.end ()) return ov->second .empty ();
614
644
645
+ if (!m_network.empty ()) {
646
+ const auto & cfs = m_config_args.find (ArgsManagerHelper::NetworkArg (*this , strArg));
647
+ if (cfs != m_config_args.end ()) return cfs->second .empty ();
648
+ }
649
+
615
650
const auto & cf = m_config_args.find (strArg);
616
651
if (cf != m_config_args.end ()) return cf->second .empty ();
617
652
0 commit comments