Skip to content

Commit db08edb

Browse files
committed
Replace IsArgKnown() with FlagsOfKnownArg()
1 parent dde80c2 commit db08edb

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/util/system.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
373373

374374
for (int i = 1; i < argc; i++) {
375375
std::string key(argv[i]);
376+
if (key == "-") break; //bitcoin-tx using stdin
376377
std::string val;
377378
size_t is_index = key.find('=');
378379
if (is_index != std::string::npos) {
@@ -392,15 +393,13 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
392393
if (key.length() > 1 && key[1] == '-')
393394
key.erase(0, 1);
394395

395-
// Check that the arg is known
396-
if (!(IsSwitchChar(key[0]) && key.size() == 1)) {
397-
if (!IsArgKnown(key)) {
398-
error = strprintf("Invalid parameter %s", key.c_str());
399-
return false;
400-
}
396+
const unsigned int flags = FlagsOfKnownArg(key);
397+
if (flags) {
398+
InterpretOption(key, val, m_override_args);
399+
} else {
400+
error = strprintf("Invalid parameter %s", key.c_str());
401+
return false;
401402
}
402-
403-
InterpretOption(key, val, m_override_args);
404403
}
405404

406405
// 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
416415
return true;
417416
}
418417

419-
bool ArgsManager::IsArgKnown(const std::string& key) const
418+
unsigned int ArgsManager::FlagsOfKnownArg(const std::string& key) const
420419
{
421420
assert(key[0] == '-');
422421

@@ -434,9 +433,12 @@ bool ArgsManager::IsArgKnown(const std::string& key) const
434433

435434
LOCK(cs_args);
436435
for (const auto& arg_map : m_available_args) {
437-
if (arg_map.second.count(base_arg_name)) return true;
436+
const auto search = arg_map.second.find(base_arg_name);
437+
if (search != arg_map.second.end()) {
438+
return search->second.m_flags;
439+
}
438440
}
439-
return false;
441+
return ArgsManager::NONE;
440442
}
441443

442444
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
835837
}
836838
for (const std::pair<std::string, std::string>& option : options) {
837839
const std::string strKey = std::string("-") + option.first;
838-
// Check that the arg is known
839-
if (!IsArgKnown(strKey)) {
840-
if (!ignore_invalid_keys) {
840+
const unsigned int flags = FlagsOfKnownArg(strKey);
841+
if (flags) {
842+
InterpretOption(strKey, option.second, m_config_args);
843+
} else {
844+
if (ignore_invalid_keys) {
845+
LogPrintf("Ignoring unknown configuration value %s\n", option.first);
846+
} else {
841847
error = strprintf("Invalid configuration value %s", option.first.c_str());
842848
return false;
843-
} else {
844-
LogPrintf("Ignoring unknown configuration value %s\n", option.first);
845-
continue;
846849
}
847850
}
848-
849-
InterpretOption(strKey, option.second, m_config_args);
850851
}
851852
return true;
852853
}

src/util/system.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,10 @@ class ArgsManager
293293
std::string GetHelpMessage() const;
294294

295295
/**
296-
* Check whether we know of this arg
296+
* Return Flags for known arg.
297+
* Return ArgsManager::NONE for unknown arg.
297298
*/
298-
bool IsArgKnown(const std::string& key) const;
299+
unsigned int FlagsOfKnownArg(const std::string& key) const;
299300
};
300301

301302
extern ArgsManager gArgs;

0 commit comments

Comments
 (0)