mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 03:02:37 +02: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;
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@ enum class OptionsCategory {
|
||||
GUI,
|
||||
COMMANDS,
|
||||
REGISTER_COMMANDS,
|
||||
CLI_COMMANDS,
|
||||
|
||||
HIDDEN // Always the last option to avoid printing these in the help
|
||||
};
|
||||
@@ -363,6 +364,13 @@ protected:
|
||||
m_network_only_args.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check CLI command args
|
||||
*
|
||||
* @throws std::runtime_error when multiple CLI_COMMAND arguments are specified
|
||||
*/
|
||||
void CheckMultipleCLIArgs() const;
|
||||
|
||||
/**
|
||||
* Get the help string
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user