aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2018-04-04 18:03:00 +1000
committerAnthony Towns <aj@erisian.com.au>2018-04-11 23:15:28 +1000
commit95eb66d5842e5ccdeb7481b9ee92ac4aface6b0f (patch)
tree25e37463abd88f57e9ce9767bf49f4f5e1b51955 /src/util.cpp
parent4d34fcc7138f0ffc831f0f8601c50cc7f494c197 (diff)
ArgsManager: support config file sections
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 3e69574022..85c3d221af 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -460,6 +460,13 @@ class ArgsManagerHelper {
public:
typedef std::map<std::string, std::vector<std::string>> MapArgs;
+ /** Convert regular argument into the network-specific setting */
+ static inline std::string NetworkArg(const ArgsManager& am, const std::string& arg)
+ {
+ assert(arg.length() > 1 && arg[0] == '-');
+ return "-" + am.m_network + "." + arg.substr(1);
+ }
+
/** Find arguments in a map and add them to a vector */
static inline void AddArgs(std::vector<std::string>& res, const MapArgs& map_args, const std::string& arg)
{
@@ -507,6 +514,13 @@ public:
// But in contrast we return the first argument seen in a config file,
// so "foo=bar \n foo=baz" in the config file gives
// GetArg(am,"foo")={true,"bar"}
+ if (!am.m_network.empty()) {
+ found_result = GetArgHelper(am.m_config_args, NetworkArg(am, arg));
+ if (found_result.first) {
+ return found_result;
+ }
+ }
+
found_result = GetArgHelper(am.m_config_args, arg);
if (found_result.first) {
return found_result;
@@ -539,9 +553,17 @@ public:
*/
static bool InterpretNegatedOption(std::string& key, std::string& val)
{
- if (key.substr(0, 3) == "-no") {
+ assert(key[0] == '-');
+
+ size_t option_index = key.find('.');
+ if (option_index == std::string::npos) {
+ option_index = 1;
+ } else {
+ ++option_index;
+ }
+ if (key.substr(option_index, 2) == "no") {
bool bool_val = InterpretBool(val);
- key.erase(1, 2);
+ key.erase(option_index, 2);
if (!bool_val ) {
// Double negatives like -nofoo=0 are supported (but discouraged)
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)
return false;
}
+void ArgsManager::SelectConfigNetwork(const std::string& network)
+{
+ m_network = network;
+}
+
void ArgsManager::ParseParameters(int argc, const char* const argv[])
{
LOCK(cs_args);
@@ -595,6 +622,9 @@ std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const
LOCK(cs_args);
ArgsManagerHelper::AddArgs(result, m_override_args, strArg);
+ if (!m_network.empty()) {
+ ArgsManagerHelper::AddArgs(result, m_config_args, ArgsManagerHelper::NetworkArg(*this, strArg));
+ }
ArgsManagerHelper::AddArgs(result, m_config_args, strArg);
return result;
}
@@ -612,6 +642,11 @@ bool ArgsManager::IsArgNegated(const std::string& strArg) const
const auto& ov = m_override_args.find(strArg);
if (ov != m_override_args.end()) return ov->second.empty();
+ if (!m_network.empty()) {
+ const auto& cfs = m_config_args.find(ArgsManagerHelper::NetworkArg(*this, strArg));
+ if (cfs != m_config_args.end()) return cfs->second.empty();
+ }
+
const auto& cf = m_config_args.find(strArg);
if (cf != m_config_args.end()) return cf->second.empty();