diff options
author | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2019-07-27 14:41:27 +0300 |
---|---|---|
committer | Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> | 2019-07-27 22:52:18 +0300 |
commit | db08edb3038a085d3dbce7bb4ec3c1d9b9a5b281 (patch) | |
tree | b3742e01067366680da9051dab62261b7cd9e0ac /src | |
parent | dde80c272ae584410532f48d23866d7d8581a1cc (diff) |
Replace IsArgKnown() with FlagsOfKnownArg()
Diffstat (limited to 'src')
-rw-r--r-- | src/util/system.cpp | 39 | ||||
-rw-r--r-- | src/util/system.h | 5 |
2 files changed, 23 insertions, 21 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index b8aa168082..c7e342a59e 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -373,6 +373,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin for (int i = 1; i < argc; i++) { std::string key(argv[i]); + if (key == "-") break; //bitcoin-tx using stdin std::string val; size_t is_index = key.find('='); if (is_index != std::string::npos) { @@ -392,15 +393,13 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin if (key.length() > 1 && key[1] == '-') key.erase(0, 1); - // Check that the arg is known - if (!(IsSwitchChar(key[0]) && key.size() == 1)) { - if (!IsArgKnown(key)) { - error = strprintf("Invalid parameter %s", key.c_str()); - return false; - } + const unsigned int flags = FlagsOfKnownArg(key); + if (flags) { + InterpretOption(key, val, m_override_args); + } else { + error = strprintf("Invalid parameter %s", key.c_str()); + return false; } - - InterpretOption(key, val, m_override_args); } // we do not allow -includeconf from command line, so we clear it here @@ -416,7 +415,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin return true; } -bool ArgsManager::IsArgKnown(const std::string& key) const +unsigned int ArgsManager::FlagsOfKnownArg(const std::string& key) const { assert(key[0] == '-'); @@ -434,9 +433,12 @@ bool ArgsManager::IsArgKnown(const std::string& key) const LOCK(cs_args); for (const auto& arg_map : m_available_args) { - if (arg_map.second.count(base_arg_name)) return true; + const auto search = arg_map.second.find(base_arg_name); + if (search != arg_map.second.end()) { + return search->second.m_flags; + } } - return false; + return ArgsManager::NONE; } std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const @@ -835,18 +837,17 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file } for (const std::pair<std::string, std::string>& option : options) { const std::string strKey = std::string("-") + option.first; - // Check that the arg is known - if (!IsArgKnown(strKey)) { - if (!ignore_invalid_keys) { + const unsigned int flags = FlagsOfKnownArg(strKey); + if (flags) { + InterpretOption(strKey, option.second, m_config_args); + } else { + if (ignore_invalid_keys) { + LogPrintf("Ignoring unknown configuration value %s\n", option.first); + } else { error = strprintf("Invalid configuration value %s", option.first.c_str()); return false; - } else { - LogPrintf("Ignoring unknown configuration value %s\n", option.first); - continue; } } - - InterpretOption(strKey, option.second, m_config_args); } return true; } diff --git a/src/util/system.h b/src/util/system.h index 9f8d94f520..75e8096826 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -293,9 +293,10 @@ public: std::string GetHelpMessage() const; /** - * Check whether we know of this arg + * Return Flags for known arg. + * Return ArgsManager::NONE for unknown arg. */ - bool IsArgKnown(const std::string& key) const; + unsigned int FlagsOfKnownArg(const std::string& key) const; }; extern ArgsManager gArgs; |