mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-20 04:30:31 +01:00
common/args.h: automate check for multiple cli commands
Co-authored-by: Anthony Towns <aj@erisian.com.au>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include <util/fs.h>
|
||||
#include <util/fs_helpers.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
|
||||
#ifdef WIN32
|
||||
#include <codecvt> /* for codecvt_utf8_utf16 */
|
||||
@@ -587,6 +588,23 @@ void ArgsManager::AddHiddenArgs(const std::vector<std::string>& names)
|
||||
}
|
||||
}
|
||||
|
||||
void ArgsManager::CheckMultipleCLIArgs() const
|
||||
{
|
||||
LOCK(cs_args);
|
||||
std::vector<std::string> found{};
|
||||
auto cmds = m_available_args.find(OptionsCategory::CLI_COMMANDS);
|
||||
if (cmds != m_available_args.end()) {
|
||||
for (const auto& [cmd, argspec] : cmds->second) {
|
||||
if (IsArgSet(cmd)) {
|
||||
found.push_back(cmd);
|
||||
}
|
||||
}
|
||||
if (found.size() > 1) {
|
||||
throw std::runtime_error(strprintf("Only one of %s may be specified.", util::Join(found, ", ")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string ArgsManager::GetHelpMessage() const
|
||||
{
|
||||
const bool show_debug = GetBoolArg("-help-debug", false);
|
||||
@@ -634,6 +652,9 @@ std::string ArgsManager::GetHelpMessage() const
|
||||
case OptionsCategory::REGISTER_COMMANDS:
|
||||
usage += HelpMessageGroup("Register Commands:");
|
||||
break;
|
||||
case OptionsCategory::CLI_COMMANDS:
|
||||
usage += HelpMessageGroup("CLI Commands:");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user