Replace IsArgKnown() with FlagsOfKnownArg()
This commit is contained in:
2 files changed
+23
-21
No files matched your search
+20
-19
@@ -373,6 +373,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
|
|||||||
|
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
std::string key(argv[i]);
|
std::string key(argv[i]);
|
||||||
|
if (key == "-") break; //bitcoin-tx using stdin
|
||||||
std::string val;
|
std::string val;
|
||||||
size_t is_index = key.find('=');
|
size_t is_index = key.find('=');
|
||||||
if (is_index != std::string::npos) {
|
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] == '-')
|
if (key.length() > 1 && key[1] == '-')
|
||||||
key.erase(0, 1);
|
key.erase(0, 1);
|
||||||
|
|
||||||
// Check that the arg is known
|
const unsigned int flags = FlagsOfKnownArg(key);
|
||||||
if (!(IsSwitchChar(key[0]) && key.size() == 1)) {
|
if (flags) {
|
||||||
if (!IsArgKnown(key)) {
|
InterpretOption(key, val, m_override_args);
|
||||||
error = strprintf("Invalid parameter %s", key.c_str());
|
} else {
|
||||||
return false;
|
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
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ArgsManager::IsArgKnown(const std::string& key) const
|
unsigned int ArgsManager::FlagsOfKnownArg(const std::string& key) const
|
||||||
{
|
{
|
||||||
assert(key[0] == '-');
|
assert(key[0] == '-');
|
||||||
|
|
||||||
@@ -434,9 +433,12 @@ bool ArgsManager::IsArgKnown(const std::string& key) const
|
|||||||
|
|
||||||
LOCK(cs_args);
|
LOCK(cs_args);
|
||||||
for (const auto& arg_map : m_available_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
|
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) {
|
for (const std::pair<std::string, std::string>& option : options) {
|
||||||
const std::string strKey = std::string("-") + option.first;
|
const std::string strKey = std::string("-") + option.first;
|
||||||
// Check that the arg is known
|
const unsigned int flags = FlagsOfKnownArg(strKey);
|
||||||
if (!IsArgKnown(strKey)) {
|
if (flags) {
|
||||||
if (!ignore_invalid_keys) {
|
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());
|
error = strprintf("Invalid configuration value %s", option.first.c_str());
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
LogPrintf("Ignoring unknown configuration value %s\n", option.first);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
InterpretOption(strKey, option.second, m_config_args);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-2
@@ -293,9 +293,10 @@ public:
|
|||||||
std::string GetHelpMessage() const;
|
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;
|
extern ArgsManager gArgs;
|
||||||
|
|||||||
Reference in new issue
Block a user