Skip to content

Commit

Permalink
Merge bitcoin#15358: util: Add SetupHelpOptions()
Browse files Browse the repository at this point in the history
a99999c util: Add SetupHelpOptions() (MarcoFalke)

Pull request description:

  Every binary we have sets up the help option in their own way and wording.

  Solve that by having one function take care of it for all of them.

Tree-SHA512: 6e947fa8bc2a46fa6ca9f45777020aa269a5df0dd916ebc863224f9a1e0f79e8e7754a1478567307edd9461e8babd77d26bc2710bbd56e8f8da9020aa85a8c9c
  • Loading branch information
laanwj authored and vijaydasmp committed Sep 13, 2021
1 parent c46ea0f commit d571a13
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 24 deletions.
2 changes: 1 addition & 1 deletion doc/man/dash-cli.1
Expand Up @@ -16,7 +16,7 @@ dash\-cli [options] help <command> Get help for a command
.HP
\-?
.IP
This help message
Print this help message and exit
.HP
\fB\-conf=\fR<file>
.IP
Expand Down
2 changes: 1 addition & 1 deletion doc/man/dash-tx.1
Expand Up @@ -15,7 +15,7 @@ Create hex\-encoded dash transaction
.HP
\-?
.IP
This help message
Print this help message and exit
.HP
\fB\-create\fR
.IP
Expand Down
6 changes: 1 addition & 5 deletions src/bench/bench_dash.cpp
Expand Up @@ -34,16 +34,12 @@ static fs::path SetDataDir()
}
static void SetupBenchArgs()
{
gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
SetupHelpOptions(gArgs);
gArgs.AddArg("-list", "List benchmarks without executing them", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), false, OptionsCategory::OPTIONS);
gArgs.AddArg("-asymptote=n1,n2,n3,...", strprintf("Test asymptotic growth of the runtime of an algorithm, if supported by the benchmark"), false, OptionsCategory::OPTIONS);
gArgs.AddArg("-output_csv=<output.csv>", "Generate CSV file with the most important benchmark results.", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-output_json=<output.json>", "Generate JSON file with all benchmark results.", false, OptionsCategory::OPTIONS);

// Hidden
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
}

// parses a comma separated list like "10,20,30,50"
Expand Down
8 changes: 2 additions & 6 deletions src/dash-cli.cpp
Expand Up @@ -35,10 +35,11 @@ static const int CONTINUE_EXECUTION=-1;

static void SetupCliArgs()
{
SetupHelpOptions(gArgs);

const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);

gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
gArgs.AddArg("-datadir=<dir>", "Specify data directory", false, OptionsCategory::OPTIONS);
Expand All @@ -54,12 +55,7 @@ static void SetupCliArgs()
gArgs.AddArg("-rpcwallet=<walletname>", "Send RPC for non-default wallet on RPC server (needs to exactly match corresponding -wallet option passed to dashd). This changes the RPC endpoint used, e.g. http://127.0.0.1:9998/wallet/<walletname>", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-stdin", "Read extra arguments from standard input, one per line until EOF/Ctrl-D (recommended for sensitive information such as passphrases). When combined with -stdinrpcpass, the first line from standard input is used for the RPC password.", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-stdinrpcpass", "Read RPC password from standard input as a single line. When combined with -stdin, the first line from standard input is used for the RPC password.", false, OptionsCategory::OPTIONS);

SetupChainParamsBaseOptions();

// Hidden
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
}

/** libevent event log callback */
Expand Down
7 changes: 2 additions & 5 deletions src/dash-tx.cpp
Expand Up @@ -36,7 +36,8 @@ const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;

static void SetupBitcoinTxArgs()
{
gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS);
SetupHelpOptions(gArgs);

gArgs.AddArg("-create", "Create new, empty TX.", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-json", "Select JSON output", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-txid", "Output only the hex-encoded transaction id of the resultant transaction.", false, OptionsCategory::OPTIONS);
Expand All @@ -63,10 +64,6 @@ static void SetupBitcoinTxArgs()

gArgs.AddArg("load=NAME:FILENAME", "Load JSON file FILENAME into register NAME", false, OptionsCategory::REGISTER_COMMANDS);
gArgs.AddArg("set=NAME:JSON-STRING", "Set register NAME to given JSON-STRING", false, OptionsCategory::REGISTER_COMMANDS);

// Hidden
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
}

//
Expand Down
12 changes: 6 additions & 6 deletions src/init.cpp
Expand Up @@ -468,20 +468,21 @@ std::string GetSupportedSocketEventsStr()

void SetupServerArgs()
{
SetupHelpOptions(gArgs);
gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", false, OptionsCategory::DEBUG_TEST); // server-only for now

const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const auto defaultChainParams = CreateChainParams(CBaseChainParams::MAIN);
const auto testnetChainParams = CreateChainParams(CBaseChainParams::TESTNET);

// Hidden Options
std::vector<std::string> hidden_args = {"-h", "-help", "-dbcrashratio", "-forcecompactdb", "-printcrashinfo",
std::vector<std::string> hidden_args = {
"-dbcrashratio", "-forcecompactdb", "-printcrashinfo",
// GUI args. These will be overwritten by SetupUIArgs for the GUI
"-allowselfsignedrootcertificates", "-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-rootcertificates=<file>", "-splash", "-uiplatform"};


// Set all of the args and their help
// When adding new options to the categories, please keep and ensure alphabetical ordering.
gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-alertnotify=<cmd>", "Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)", false, OptionsCategory::OPTIONS);
gArgs.AddArg("-assumevalid=<hex>", strprintf("If this block is in the chain assume that it and its ancestors are valid and potentially skip their script verification (0 to verify all, default: %s, testnet: %s)", defaultChainParams->GetConsensus().defaultAssumeValid.GetHex(), testnetChainParams->GetConsensus().defaultAssumeValid.GetHex()), false, OptionsCategory::OPTIONS);
gArgs.AddArg("-blocksdir=<dir>", "Specify directory to hold blocks subdirectory for *.dat files (default: <datadir>)", false, OptionsCategory::OPTIONS);
Expand Down Expand Up @@ -681,7 +682,6 @@ void SetupServerArgs()
"If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + ListLogCategories() + ".", false, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-debugexclude=<category>", strprintf("Exclude debugging information for a category. Can be used in conjunction with -debug=1 to output debug logs for all categories except one or more specified categories."), false, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-disablegovernance", strprintf("Disable governance validation (0-1, default: %u)", 0), false, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", false, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), false, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), true, OptionsCategory::DEBUG_TEST);
gArgs.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), false, OptionsCategory::DEBUG_TEST);
Expand Down
6 changes: 6 additions & 0 deletions src/util/system.cpp
Expand Up @@ -742,6 +742,12 @@ bool HelpRequested(const ArgsManager& args)
return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help") || args.IsArgSet("-help-debug");
}

void SetupHelpOptions(ArgsManager& args)
{
args.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
args.AddHiddenArgs({"-h", "-help"});
}

static const int screenWidth = 79;
static const int optIndent = 2;
static const int msgIndent = 7;
Expand Down
3 changes: 3 additions & 0 deletions src/util/system.h
Expand Up @@ -323,6 +323,9 @@ extern ArgsManager gArgs;
*/
bool HelpRequested(const ArgsManager& args);

/** Add help options to the args manager */
void SetupHelpOptions(ArgsManager& args);

/**
* Format a string to be used as group of options in help messages
*
Expand Down

0 comments on commit d571a13

Please sign in to comment.