Make gArgs aware of the arguments

gArgs knows what the available arguments are and their help. Getting
the help message is moved to gArgs and HelpMessage() is removed
This commit is contained in:
Andrew Chow
2018-04-28 16:54:58 -04:00
parent 08c1caf863
commit 4d4185a4f0
17 changed files with 345 additions and 310 deletions

View File

@@ -547,6 +547,55 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV
m_override_args[strArg] = {strValue};
}
void ArgsManager::AddArg(const std::string& name, const std::string& help, const bool debug_only, const OptionsCategory& cat)
{
std::pair<OptionsCategory, std::string> key(cat, name);
assert(m_available_args.count(key) == 0);
m_available_args.emplace(key, std::pair<std::string, bool>(help, debug_only));
}
std::string ArgsManager::GetHelpMessage()
{
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
std::string usage = HelpMessageGroup(_("Options:"));
OptionsCategory last_cat = OptionsCategory::OPTIONS;
for (auto& arg : m_available_args) {
if (arg.first.first != last_cat) {
last_cat = arg.first.first;
if (last_cat == OptionsCategory::CONNECTION)
usage += HelpMessageGroup(_("Connection options:"));
else if (last_cat == OptionsCategory::ZMQ)
usage += HelpMessageGroup(_("ZeroMQ notification options:"));
else if (last_cat == OptionsCategory::DEBUG_TEST)
usage += HelpMessageGroup(_("Debugging/Testing options:"));
else if (last_cat == OptionsCategory::NODE_RELAY)
usage += HelpMessageGroup(_("Node relay options:"));
else if (last_cat == OptionsCategory::BLOCK_CREATION)
usage += HelpMessageGroup(_("Block creation options:"));
else if (last_cat == OptionsCategory::RPC)
usage += HelpMessageGroup(_("RPC server options:"));
else if (last_cat == OptionsCategory::WALLET)
usage += HelpMessageGroup(_("Wallet options:"));
else if (last_cat == OptionsCategory::WALLET_DEBUG_TEST && show_debug)
usage += HelpMessageGroup(_("Wallet debugging/testing options:"));
else if (last_cat == OptionsCategory::CHAINPARAMS)
usage += HelpMessageGroup(_("Chain selection options:"));
else if (last_cat == OptionsCategory::GUI)
usage += HelpMessageGroup(_("UI Options:"));
else if (last_cat == OptionsCategory::COMMANDS)
usage += HelpMessageGroup(_("Commands:"));
else if (last_cat == OptionsCategory::REGISTER_COMMANDS)
usage += HelpMessageGroup(_("Register Commands:"));
}
if (show_debug || !arg.second.second) {
usage += HelpMessageOpt(arg.first.second, arg.second.first);
}
}
return usage;
}
bool HelpRequested(const ArgsManager& args)
{
return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help");