diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2019-11-11 19:05:12 -0500 |
---|---|---|
committer | Russell Yanofsky <russ@yanofsky.org> | 2019-11-13 04:20:30 -0500 |
commit | dc0f1480746b34aa3ca2d9c0f1ec764083026b40 (patch) | |
tree | 71bf0642facbb3f60abab127e03b7d7be2b4ff44 /src/util/system.cpp | |
parent | 57e8b7a7273567aa4a4aee87cce18e9bff8f3196 (diff) |
refactor: Replace FlagsOfKnownArg with GetArgFlags
Rename suggested by João Barbosa <joao.paulo.barbosa@gmail.com>
https://github.com/bitcoin/bitcoin/pull/16545#issuecomment-519048000
This also gets rid of ArgsManager::NONE constant, which was an implementation
detail not meant to be used by ArgsManager callers.
Finally this reverts a change from 7f40528cd50fc43ac0bd3e785de24d661adddb7a
https://github.com/bitcoin/bitcoin/pull/15934 adding "-" characters to argument
names. Better for GetArgFlags to require "-" prefixes for consistency with
other ArgsManager methods, and to be more efficient later when GetArg functions
need to call GetArgFlags (https://github.com/bitcoin/bitcoin/pull/16545)
This commit does not change behavior.
Diffstat (limited to 'src/util/system.cpp')
-rw-r--r-- | src/util/system.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/util/system.cpp b/src/util/system.cpp index 9043d02f0a..9601777b31 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -326,9 +326,9 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin key.erase(0, 1); std::string section; util::SettingsValue value = InterpretOption(section, key, val); - const unsigned int flags = FlagsOfKnownArg(key); + Optional<unsigned int> flags = GetArgFlags('-' + key); if (flags) { - if (!CheckValid(key, value, flags, error)) { + if (!CheckValid(key, value, *flags, error)) { return false; } // Weird behavior preserved for backwards compatibility: command @@ -355,16 +355,16 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin return success; } -unsigned int ArgsManager::FlagsOfKnownArg(const std::string& key) const +Optional<unsigned int> ArgsManager::GetArgFlags(const std::string& name) const { LOCK(cs_args); for (const auto& arg_map : m_available_args) { - const auto search = arg_map.second.find('-' + key); + const auto search = arg_map.second.find(name); if (search != arg_map.second.end()) { return search->second.m_flags; } } - return ArgsManager::NONE; + return nullopt; } std::vector<std::string> ArgsManager::GetArgs(const std::string& strArg) const @@ -745,9 +745,9 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& file std::string section; std::string key = option.first; util::SettingsValue value = InterpretOption(section, key, option.second); - const unsigned int flags = FlagsOfKnownArg(key); + Optional<unsigned int> flags = GetArgFlags('-' + key); if (flags) { - if (!CheckValid(key, value, flags, error)) { + if (!CheckValid(key, value, *flags, error)) { return false; } m_settings.ro_config[section][key].push_back(value); |