Skip to content

Commit 9544a3f

Browse files
committed
tiny refactor for ArgsManager
This commit contains 2 refactors. 1. mark "const" on ArgsManager::GetHelpMessage and IsArgKnown. 2. remove unused "error" argument from ArgsManager::IsArgKnown. Firstly, I mark "const" on where it is possible to. It is mentioned before (e.g. bitcoin/bitcoin#13190 (review)). And about 2nd change, ArgsManager::IsArgKnown was added at commit #4f8704d which was merged at PR #13112. But from its beggining, "error" argument never be used. I think it should be refactored.
1 parent 07ce278 commit 9544a3f

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/util.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
446446

447447
// Check that the arg is known
448448
if (!(IsSwitchChar(key[0]) && key.size() == 1)) {
449-
if (!IsArgKnown(key, error)) {
449+
if (!IsArgKnown(key)) {
450450
error = strprintf("Invalid parameter %s", key.c_str());
451451
return false;
452452
}
@@ -466,7 +466,7 @@ bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::strin
466466
return true;
467467
}
468468

469-
bool ArgsManager::IsArgKnown(const std::string& key, std::string& error)
469+
bool ArgsManager::IsArgKnown(const std::string& key) const
470470
{
471471
size_t option_index = key.find('.');
472472
std::string arg_no_net;
@@ -591,7 +591,7 @@ void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
591591
}
592592
}
593593

594-
std::string ArgsManager::GetHelpMessage()
594+
std::string ArgsManager::GetHelpMessage() const
595595
{
596596
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
597597

@@ -859,7 +859,7 @@ bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, boo
859859
}
860860

861861
// Check that the arg is known
862-
if (!IsArgKnown(strKey, error) && !ignore_invalid_keys) {
862+
if (!IsArgKnown(strKey) && !ignore_invalid_keys) {
863863
error = strprintf("Invalid configuration value %s", option.first.c_str());
864864
return false;
865865
}

src/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,12 @@ class ArgsManager
276276
/**
277277
* Get the help string
278278
*/
279-
std::string GetHelpMessage();
279+
std::string GetHelpMessage() const;
280280

281281
/**
282282
* Check whether we know of this arg
283283
*/
284-
bool IsArgKnown(const std::string& key, std::string& error);
284+
bool IsArgKnown(const std::string& key) const;
285285
};
286286

287287
extern ArgsManager gArgs;

0 commit comments

Comments
 (0)