aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2018-05-16 15:15:18 -0400
committerAndrew Chow <achow101-github@achow101.com>2018-05-30 11:09:15 -0400
commit174f7c80801383cde5ea514b19fb8b108b56b31c (patch)
treeede8b06838566830fe4b782b7469770a9c066bf0
parentfd96d54f39cf4f66890e0bb40812d47e69728cec (diff)
downloadbitcoin-174f7c80801383cde5ea514b19fb8b108b56b31c.tar.xz
Use a struct for arguments and nested map for categories
Instead of a single map with the category and name as the key, make m_available_args contain maps. The key will be the category and the value is a map which actually contains the arguments for that category. The nested map's key is the argument name, while the value is a struct that contains the help text and whether the argument is a debug only argument.
-rw-r--r--src/util.cpp80
-rw-r--r--src/util.h11
2 files changed, 66 insertions, 25 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 963a7f531f..7f9a1d5609 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -549,48 +549,80 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV
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));
+ // Split arg name from its help param
+ size_t eq_index = name.find('=');
+ if (eq_index == std::string::npos) {
+ eq_index = name.size();
+ }
+
+ std::map<std::string, Arg>& arg_map = m_available_args[cat];
+ auto ret = arg_map.emplace(name.substr(0, eq_index), Arg(name.substr(eq_index, name.size() - eq_index), help, debug_only));
+ assert(ret.second); // Make sure an insertion actually happened
}
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)
+ std::string usage = "";
+ for (const auto& arg_map : m_available_args) {
+ switch(arg_map.first) {
+ case OptionsCategory::OPTIONS:
+ usage += HelpMessageGroup("Options:");
+ break;
+ case OptionsCategory::CONNECTION:
usage += HelpMessageGroup("Connection options:");
- else if (last_cat == OptionsCategory::ZMQ)
+ break;
+ case OptionsCategory::ZMQ:
usage += HelpMessageGroup("ZeroMQ notification options:");
- else if (last_cat == OptionsCategory::DEBUG_TEST)
+ break;
+ case OptionsCategory::DEBUG_TEST:
usage += HelpMessageGroup("Debugging/Testing options:");
- else if (last_cat == OptionsCategory::NODE_RELAY)
+ break;
+ case OptionsCategory::NODE_RELAY:
usage += HelpMessageGroup("Node relay options:");
- else if (last_cat == OptionsCategory::BLOCK_CREATION)
+ break;
+ case OptionsCategory::BLOCK_CREATION:
usage += HelpMessageGroup("Block creation options:");
- else if (last_cat == OptionsCategory::RPC)
+ break;
+ case OptionsCategory::RPC:
usage += HelpMessageGroup("RPC server options:");
- else if (last_cat == OptionsCategory::WALLET)
+ break;
+ case 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)
+ break;
+ case OptionsCategory::WALLET_DEBUG_TEST:
+ if (show_debug) usage += HelpMessageGroup("Wallet debugging/testing options:");
+ break;
+ case OptionsCategory::CHAINPARAMS:
usage += HelpMessageGroup("Chain selection options:");
- else if (last_cat == OptionsCategory::GUI)
+ break;
+ case OptionsCategory::GUI:
usage += HelpMessageGroup("UI Options:");
- else if (last_cat == OptionsCategory::COMMANDS)
+ break;
+ case OptionsCategory::COMMANDS:
usage += HelpMessageGroup("Commands:");
- else if (last_cat == OptionsCategory::REGISTER_COMMANDS)
+ break;
+ case OptionsCategory::REGISTER_COMMANDS:
usage += HelpMessageGroup("Register Commands:");
+ break;
+ default:
+ break;
}
- if (show_debug || !arg.second.second) {
- usage += HelpMessageOpt(arg.first.second, arg.second.first);
+
+ // When we get to the hidden options, stop
+ if (arg_map.first == OptionsCategory::HIDDEN) break;
+
+ for (const auto& arg : arg_map.second) {
+ if (show_debug || !arg.second.m_debug_only) {
+ std::string name;
+ if (arg.second.m_help_param.empty()) {
+ name = arg.first;
+ } else {
+ name = arg.first + arg.second.m_help_param;
+ }
+ usage += HelpMessageOpt(name, arg.second.m_help_text);
+ }
}
}
return usage;
diff --git a/src/util.h b/src/util.h
index 17dd5c0683..1d318e2851 100644
--- a/src/util.h
+++ b/src/util.h
@@ -140,12 +140,21 @@ class ArgsManager
protected:
friend class ArgsManagerHelper;
+ struct Arg
+ {
+ std::string m_help_param;
+ std::string m_help_text;
+ bool m_debug_only;
+
+ Arg(const std::string& help_param, const std::string& help_text, bool debug_only) : m_help_param(help_param), m_help_text(help_text), m_debug_only(debug_only) {};
+ };
+
mutable CCriticalSection cs_args;
std::map<std::string, std::vector<std::string>> m_override_args;
std::map<std::string, std::vector<std::string>> m_config_args;
std::string m_network;
std::set<std::string> m_network_only_args;
- std::map<std::pair<OptionsCategory, std::string>, std::pair<std::string, bool>> m_available_args;
+ std::map<OptionsCategory, std::map<std::string, Arg>> m_available_args;
void ReadConfigStream(std::istream& stream);