Skip to content

Commit 6543570

Browse files
committed
Merge #15358: util: Add SetupHelpOptions()
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
2 parents 1bc149d + a99999c commit 6543570

File tree

10 files changed

+23
-28
lines changed

10 files changed

+23
-28
lines changed

doc/man/bitcoin-cli.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Bitcoin Core RPC client version v0.17.99.0
2020
.HP
2121
\-?
2222
.IP
23-
This help message
23+
Print this help message and exit
2424
.HP
2525
\fB\-conf=\fR<file>
2626
.IP

doc/man/bitcoin-tx.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Bitcoin Core bitcoin\-tx utility version v0.17.99.0
1414
.HP
1515
\-?
1616
.IP
17-
This help message
17+
Print this help message and exit
1818
.HP
1919
\fB\-create\fR
2020
.IP

doc/man/bitcoin-wallet.1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ bitcoin\-wallet [options] <command>
1515
.HP
1616
\-?
1717
.IP
18-
This help message
18+
Print this help message and exit
1919
.HP
2020
\fB\-datadir=\fR<dir>
2121
.IP

src/bench/bench_bitcoin.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ static const int64_t DEFAULT_PLOT_HEIGHT = 768;
2424

2525
static void SetupBenchArgs()
2626
{
27-
gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
27+
SetupHelpOptions(gArgs);
28+
2829
gArgs.AddArg("-list", "List benchmarks without executing them. Can be combined with -scaling and -filter", false, OptionsCategory::OPTIONS);
2930
gArgs.AddArg("-evals=<n>", strprintf("Number of measurement evaluations to perform. (default: %u)", DEFAULT_BENCH_EVALUATIONS), false, OptionsCategory::OPTIONS);
3031
gArgs.AddArg("-filter=<regex>", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), false, OptionsCategory::OPTIONS);
@@ -33,10 +34,6 @@ static void SetupBenchArgs()
3334
gArgs.AddArg("-plot-plotlyurl=<uri>", strprintf("URL to use for plotly.js (default: %s)", DEFAULT_PLOT_PLOTLYURL), false, OptionsCategory::OPTIONS);
3435
gArgs.AddArg("-plot-width=<x>", strprintf("Plot width in pixel (default: %u)", DEFAULT_PLOT_WIDTH), false, OptionsCategory::OPTIONS);
3536
gArgs.AddArg("-plot-height=<x>", strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), false, OptionsCategory::OPTIONS);
36-
37-
// Hidden
38-
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
39-
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
4037
}
4138

4239
static fs::path SetDataDir()

src/bitcoin-cli.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ static const int CONTINUE_EXECUTION=-1;
3434

3535
static void SetupCliArgs()
3636
{
37+
SetupHelpOptions(gArgs);
38+
3739
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
3840
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
3941
const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
4042

41-
gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS);
4243
gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS);
4344
gArgs.AddArg("-conf=<file>", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
4445
gArgs.AddArg("-datadir=<dir>", "Specify data directory", false, OptionsCategory::OPTIONS);
@@ -55,10 +56,6 @@ static void SetupCliArgs()
5556
gArgs.AddArg("-rpcwallet=<walletname>", "Send RPC for non-default wallet on RPC server (needs to exactly match corresponding -wallet option passed to bitcoind). This changes the RPC endpoint used, e.g. http://127.0.0.1:8332/wallet/<walletname>", false, OptionsCategory::OPTIONS);
5657
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);
5758
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);
58-
59-
// Hidden
60-
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
61-
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
6259
}
6360

6461
/** libevent event log callback */

src/bitcoin-tx.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
3535

3636
static void SetupBitcoinTxArgs()
3737
{
38-
gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS);
38+
SetupHelpOptions(gArgs);
39+
3940
gArgs.AddArg("-create", "Create new, empty TX.", false, OptionsCategory::OPTIONS);
4041
gArgs.AddArg("-json", "Select JSON output", false, OptionsCategory::OPTIONS);
4142
gArgs.AddArg("-txid", "Output only the hex-encoded transaction id of the resultant transaction.", false, OptionsCategory::OPTIONS);
@@ -66,10 +67,6 @@ static void SetupBitcoinTxArgs()
6667

6768
gArgs.AddArg("load=NAME:FILENAME", "Load JSON file FILENAME into register NAME", false, OptionsCategory::REGISTER_COMMANDS);
6869
gArgs.AddArg("set=NAME:JSON-STRING", "Set register NAME to given JSON-STRING", false, OptionsCategory::REGISTER_COMMANDS);
69-
70-
// Hidden
71-
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
72-
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
7370
}
7471

7572
//

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,16 @@ const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
2020

2121
static void SetupWalletToolArgs()
2222
{
23+
SetupHelpOptions(gArgs);
2324
SetupChainParamsBaseOptions();
2425

25-
gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS);
2626
gArgs.AddArg("-datadir=<dir>", "Specify data directory", false, OptionsCategory::OPTIONS);
2727
gArgs.AddArg("-wallet=<wallet-name>", "Specify wallet name", false, OptionsCategory::OPTIONS);
2828
gArgs.AddArg("-debug=<category>", "Output debugging information (default: 0).", false, OptionsCategory::DEBUG_TEST);
2929
gArgs.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise.", false, OptionsCategory::DEBUG_TEST);
3030

3131
gArgs.AddArg("info", "Get wallet info", false, OptionsCategory::COMMANDS);
3232
gArgs.AddArg("create", "Create new wallet file", false, OptionsCategory::COMMANDS);
33-
34-
// Hidden
35-
gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN);
36-
gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN);
3733
}
3834

3935
static bool WalletAppInit(int argc, char* argv[])

src/init.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ static void OnRPCStopped()
326326

327327
void SetupServerArgs()
328328
{
329+
SetupHelpOptions(gArgs);
330+
gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", false, OptionsCategory::DEBUG_TEST); // server-only for now
331+
329332
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
330333
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
331334
const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
@@ -334,14 +337,11 @@ void SetupServerArgs()
334337
const auto regtestChainParams = CreateChainParams(CBaseChainParams::REGTEST);
335338

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

342-
// Set all of the args and their help
343-
// When adding new options to the categories, please keep and ensure alphabetical ordering.
344-
gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
345345
gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS);
346346
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);
347347
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);
@@ -470,7 +470,6 @@ void SetupServerArgs()
470470
gArgs.AddArg("-debug=<category>", "Output debugging information (default: -nodebug, supplying <category> is optional). "
471471
"If <category> is not supplied or if <category> = 1, output all debugging information. <category> can be: " + ListLogCategories() + ".", false, OptionsCategory::DEBUG_TEST);
472472
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);
473-
gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", false, OptionsCategory::DEBUG_TEST);
474473
gArgs.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), false, OptionsCategory::DEBUG_TEST);
475474
gArgs.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), false, OptionsCategory::DEBUG_TEST);
476475
gArgs.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), true, OptionsCategory::DEBUG_TEST);

src/util/system.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,12 @@ bool HelpRequested(const ArgsManager& args)
635635
return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help") || args.IsArgSet("-help-debug");
636636
}
637637

638+
void SetupHelpOptions(ArgsManager& args)
639+
{
640+
args.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS);
641+
args.AddHiddenArgs({"-h", "-help"});
642+
}
643+
638644
static const int screenWidth = 79;
639645
static const int optIndent = 2;
640646
static const int msgIndent = 7;

src/util/system.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ extern ArgsManager gArgs;
295295
*/
296296
bool HelpRequested(const ArgsManager& args);
297297

298+
/** Add help options to the args manager */
299+
void SetupHelpOptions(ArgsManager& args);
300+
298301
/**
299302
* Format a string to be used as group of options in help messages
300303
*

0 commit comments

Comments
 (0)