Skip to content

Commit 0d1ebf4

Browse files
committed
Merge #13733: Utils: Refactor ArgsManager a little
9544a3f tiny refactor for ArgsManager (AtsukiTak) Pull request description: This PR contains some small refactors for `ArgsManager`. 1. Mark `const` on member function if it possible. 2. Remove unused `error` argument from `ArgsManager::IsArgKnown`. I'm not sure whether these refactors should be separated into another PR. If so, I will do that. Tree-SHA512: 7df09e7f7c4cdd2e7cd60e34137faa7ca7463be66490f8552fdea3656da6ccc98886e258bdeef21820d197fc2fde06ab2d3405205f5de53f258df7c191d206b0
2 parents 05714f9 + 9544a3f commit 0d1ebf4

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)