Changeset View
Changeset View
Standalone View
Standalone View
src/util.cpp
Show First 20 Lines • Show All 618 Lines • ▼ Show 20 Lines | |||||
void ArgsManager::ForceSetMultiArg(const std::string &strArg, | void ArgsManager::ForceSetMultiArg(const std::string &strArg, | ||||
const std::string &strValue) { | const std::string &strValue) { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
m_override_args[strArg].push_back(strValue); | m_override_args[strArg].push_back(strValue); | ||||
} | } | ||||
void ArgsManager::AddArg(const std::string &name, const std::string &help, | void ArgsManager::AddArg(const std::string &name, const std::string &help, | ||||
const bool debug_only, const OptionsCategory &cat) { | const bool debug_only, const OptionsCategory &cat) { | ||||
std::pair<OptionsCategory, std::string> key(cat, name); | // Split arg name from its help param | ||||
assert(m_available_args.count(key) == 0); | size_t eq_index = name.find('='); | ||||
m_available_args.emplace(key, | if (eq_index == std::string::npos) { | ||||
std::pair<std::string, bool>(help, debug_only)); | 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)); | |||||
// Make sure an insertion actually happened. | |||||
assert(ret.second); | |||||
} | } | ||||
void ArgsManager::ClearArg(const std::string &strArg) { | void ArgsManager::ClearArg(const std::string &strArg) { | ||||
LOCK(cs_args); | LOCK(cs_args); | ||||
m_override_args.erase(strArg); | m_override_args.erase(strArg); | ||||
m_config_args.erase(strArg); | m_config_args.erase(strArg); | ||||
} | } | ||||
std::string ArgsManager::GetHelpMessage() { | std::string ArgsManager::GetHelpMessage() { | ||||
const bool show_debug = gArgs.GetBoolArg("-help-debug", false); | const bool show_debug = gArgs.GetBoolArg("-help-debug", false); | ||||
std::string usage = HelpMessageGroup(_("Options:")); | std::string usage = ""; | ||||
for (const auto &arg_map : m_available_args) { | |||||
OptionsCategory last_cat = OptionsCategory::OPTIONS; | switch (arg_map.first) { | ||||
for (auto &arg : m_available_args) { | case OptionsCategory::OPTIONS: | ||||
if (arg.first.first != last_cat) { | usage += HelpMessageGroup("Options:"); | ||||
last_cat = arg.first.first; | break; | ||||
if (last_cat == OptionsCategory::CONNECTION) { | case OptionsCategory::CONNECTION: | ||||
usage += HelpMessageGroup(_("Connection options:")); | usage += HelpMessageGroup("Connection options:"); | ||||
} else if (last_cat == OptionsCategory::ZMQ) { | break; | ||||
usage += HelpMessageGroup(_("ZeroMQ notification options:")); | case OptionsCategory::ZMQ: | ||||
} else if (last_cat == OptionsCategory::DEBUG_TEST) { | usage += HelpMessageGroup("ZeroMQ notification options:"); | ||||
usage += HelpMessageGroup(_("Debugging/Testing options:")); | break; | ||||
} else if (last_cat == OptionsCategory::NODE_RELAY) { | case OptionsCategory::DEBUG_TEST: | ||||
usage += HelpMessageGroup(_("Node relay options:")); | usage += HelpMessageGroup("Debugging/Testing options:"); | ||||
} else if (last_cat == OptionsCategory::BLOCK_CREATION) { | break; | ||||
usage += HelpMessageGroup(_("Block creation options:")); | case OptionsCategory::NODE_RELAY: | ||||
} else if (last_cat == OptionsCategory::RPC) { | usage += HelpMessageGroup("Node relay options:"); | ||||
usage += HelpMessageGroup(_("RPC server options:")); | break; | ||||
} else if (last_cat == OptionsCategory::WALLET) { | case OptionsCategory::BLOCK_CREATION: | ||||
usage += HelpMessageGroup(_("Wallet options:")); | usage += HelpMessageGroup("Block creation options:"); | ||||
} else if (last_cat == OptionsCategory::WALLET_DEBUG_TEST && | break; | ||||
show_debug) { | case OptionsCategory::RPC: | ||||
usage += HelpMessageGroup("RPC server options:"); | |||||
break; | |||||
case OptionsCategory::WALLET: | |||||
usage += HelpMessageGroup("Wallet options:"); | |||||
break; | |||||
case OptionsCategory::WALLET_DEBUG_TEST: | |||||
if (show_debug) { | |||||
usage += | usage += | ||||
HelpMessageGroup(_("Wallet debugging/testing options:")); | HelpMessageGroup("Wallet debugging/testing options:"); | ||||
} else if (last_cat == OptionsCategory::CHAINPARAMS) { | } | ||||
usage += HelpMessageGroup(_("Chain selection options:")); | break; | ||||
} else if (last_cat == OptionsCategory::GUI) { | case OptionsCategory::CHAINPARAMS: | ||||
usage += HelpMessageGroup(_("UI Options:")); | usage += HelpMessageGroup("Chain selection options:"); | ||||
} else if (last_cat == OptionsCategory::COMMANDS) { | break; | ||||
usage += HelpMessageGroup(_("Commands:")); | case OptionsCategory::GUI: | ||||
} else if (last_cat == OptionsCategory::REGISTER_COMMANDS) { | usage += HelpMessageGroup("UI Options:"); | ||||
usage += HelpMessageGroup(_("Register Commands:")); | break; | ||||
case OptionsCategory::COMMANDS: | |||||
usage += HelpMessageGroup("Commands:"); | |||||
break; | |||||
case OptionsCategory::REGISTER_COMMANDS: | |||||
usage += HelpMessageGroup("Register Commands:"); | |||||
break; | |||||
default: | |||||
break; | |||||
} | |||||
// 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); | |||||
} | } | ||||
if (show_debug || !arg.second.second) { | |||||
usage += HelpMessageOpt(arg.first.second, arg.second.first); | |||||
} | } | ||||
} | } | ||||
return usage; | return usage; | ||||
} | } | ||||
bool HelpRequested(const ArgsManager &args) { | bool HelpRequested(const ArgsManager &args) { | ||||
return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help"); | return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 521 Lines • Show Last 20 Lines |