Skip to content

Commit 4d4185a

Browse files
committed
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
1 parent 08c1caf commit 4d4185a

17 files changed

+353
-318
lines changed

contrib/devtools/check-doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
FOLDER_GREP = 'src'
1818
FOLDER_TEST = 'src/test/'
1919
REGEX_ARG = '(?:ForceSet|SoftSet|Get|Is)(?:Bool)?Args?(?:Set)?\("(-[^"]+)"'
20-
REGEX_DOC = 'HelpMessageOpt\("(-[^"=]+?)(?:=|")'
20+
REGEX_DOC = 'AddArg\("(-[^"=]+?)(?:=|")'
2121
CMD_ROOT_DIR = '`git rev-parse --show-toplevel`/{}'.format(FOLDER_GREP)
2222
CMD_GREP_ARGS = r"git grep --perl-regexp '{}' -- {} ':(exclude){}'".format(REGEX_ARG, CMD_ROOT_DIR, FOLDER_TEST)
2323
CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR)

src/bench/bench_bitcoin.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,27 @@ static const char* DEFAULT_PLOT_PLOTLYURL = "https://cdn.plot.ly/plotly-latest.m
2222
static const int64_t DEFAULT_PLOT_WIDTH = 1024;
2323
static const int64_t DEFAULT_PLOT_HEIGHT = 768;
2424

25+
static void SetupBenchArgs()
26+
{
27+
gArgs.AddArg("-?", _("Print this help message and exit"), false, OptionsCategory::OPTIONS);
28+
gArgs.AddArg("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter"), false, OptionsCategory::OPTIONS);
29+
gArgs.AddArg("-evals=<n>", strprintf(_("Number of measurement evaluations to perform. (default: %u)"), DEFAULT_BENCH_EVALUATIONS), false, OptionsCategory::OPTIONS);
30+
gArgs.AddArg("-filter=<regex>", strprintf(_("Regular expression filter to select benchmark by name (default: %s)"), DEFAULT_BENCH_FILTER), false, OptionsCategory::OPTIONS);
31+
gArgs.AddArg("-scaling=<n>", strprintf(_("Scaling factor for benchmark's runtime (default: %u)"), DEFAULT_BENCH_SCALING), false, OptionsCategory::OPTIONS);
32+
gArgs.AddArg("-printer=(console|plot)", strprintf(_("Choose printer format. console: print data to console. plot: Print results as HTML graph (default: %s)"), DEFAULT_BENCH_PRINTER), false, OptionsCategory::OPTIONS);
33+
gArgs.AddArg("-plot-plotlyurl=<uri>", strprintf(_("URL to use for plotly.js (default: %s)"), DEFAULT_PLOT_PLOTLYURL), false, OptionsCategory::OPTIONS);
34+
gArgs.AddArg("-plot-width=<x>", strprintf(_("Plot width in pixel (default: %u)"), DEFAULT_PLOT_WIDTH), false, OptionsCategory::OPTIONS);
35+
gArgs.AddArg("-plot-height=<x>", strprintf(_("Plot height in pixel (default: %u)"), DEFAULT_PLOT_HEIGHT), false, OptionsCategory::OPTIONS);
36+
}
37+
2538
int
2639
main(int argc, char** argv)
2740
{
41+
SetupBenchArgs();
2842
gArgs.ParseParameters(argc, argv);
2943

3044
if (HelpRequested(gArgs)) {
31-
std::cout << HelpMessageGroup(_("Options:"))
32-
<< HelpMessageOpt("-?", _("Print this help message and exit"))
33-
<< HelpMessageOpt("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter"))
34-
<< HelpMessageOpt("-evals=<n>", strprintf(_("Number of measurement evaluations to perform. (default: %u)"), DEFAULT_BENCH_EVALUATIONS))
35-
<< HelpMessageOpt("-filter=<regex>", strprintf(_("Regular expression filter to select benchmark by name (default: %s)"), DEFAULT_BENCH_FILTER))
36-
<< HelpMessageOpt("-scaling=<n>", strprintf(_("Scaling factor for benchmark's runtime (default: %u)"), DEFAULT_BENCH_SCALING))
37-
<< HelpMessageOpt("-printer=(console|plot)", strprintf(_("Choose printer format. console: print data to console. plot: Print results as HTML graph (default: %s)"), DEFAULT_BENCH_PRINTER))
38-
<< HelpMessageOpt("-plot-plotlyurl=<uri>", strprintf(_("URL to use for plotly.js (default: %s)"), DEFAULT_PLOT_PLOTLYURL))
39-
<< HelpMessageOpt("-plot-width=<x>", strprintf(_("Plot width in pixel (default: %u)"), DEFAULT_PLOT_WIDTH))
40-
<< HelpMessageOpt("-plot-height=<x>", strprintf(_("Plot height in pixel (default: %u)"), DEFAULT_PLOT_HEIGHT));
45+
std::cout << gArgs.GetHelpMessage();
4146

4247
return 0;
4348
}

src/bitcoin-cli.cpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,26 @@ static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
2929
static const bool DEFAULT_NAMED=false;
3030
static const int CONTINUE_EXECUTION=-1;
3131

32-
static std::string HelpMessageCli()
32+
static void SetupCliArgs()
3333
{
3434
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
3535
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
36-
std::string strUsage;
37-
strUsage += HelpMessageGroup(_("Options:"));
38-
strUsage += HelpMessageOpt("-?", _("This help message"));
39-
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME));
40-
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
41-
strUsage += HelpMessageOpt("-getinfo", _("Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)"));
42-
AppendParamsHelpMessages(strUsage);
43-
strUsage += HelpMessageOpt("-named", strprintf(_("Pass named instead of positional arguments (default: %s)"), DEFAULT_NAMED));
44-
strUsage += HelpMessageOpt("-rpcclienttimeout=<n>", strprintf(_("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT));
45-
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
46-
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
47-
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()));
48-
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
49-
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
50-
strUsage += HelpMessageOpt("-rpcwallet=<walletname>", _("Send RPC for non-default wallet on RPC server (needs to exactly match corresponding -wallet option passed to bitcoind)"));
51-
strUsage += HelpMessageOpt("-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."));
52-
strUsage += HelpMessageOpt("-stdinrpcpass", strprintf(_("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.")));
53-
54-
return strUsage;
36+
37+
gArgs.AddArg("-?", _("This help message"), false, OptionsCategory::OPTIONS);
38+
gArgs.AddArg("-conf=<file>", strprintf(_("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
39+
gArgs.AddArg("-datadir=<dir>", _("Specify data directory"), false, OptionsCategory::OPTIONS);
40+
gArgs.AddArg("-getinfo", _("Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)"), false, OptionsCategory::OPTIONS);
41+
SetupChainParamsBaseOptions();
42+
gArgs.AddArg("-named", strprintf(_("Pass named instead of positional arguments (default: %s)"), DEFAULT_NAMED), false, OptionsCategory::OPTIONS);
43+
gArgs.AddArg("-rpcclienttimeout=<n>", strprintf(_("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)"), DEFAULT_HTTP_CLIENT_TIMEOUT), false, OptionsCategory::OPTIONS);
44+
gArgs.AddArg("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT), false, OptionsCategory::OPTIONS);
45+
gArgs.AddArg("-rpcpassword=<pw>", _("Password for JSON-RPC connections"), false, OptionsCategory::OPTIONS);
46+
gArgs.AddArg("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), defaultBaseParams->RPCPort(), testnetBaseParams->RPCPort()), false, OptionsCategory::OPTIONS);
47+
gArgs.AddArg("-rpcuser=<user>", _("Username for JSON-RPC connections"), false, OptionsCategory::OPTIONS);
48+
gArgs.AddArg("-rpcwait", _("Wait for RPC server to start"), false, OptionsCategory::OPTIONS);
49+
gArgs.AddArg("-rpcwallet=<walletname>", _("Send RPC for non-default wallet on RPC server (needs to exactly match corresponding -wallet option passed to bitcoind)"), false, OptionsCategory::OPTIONS);
50+
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);
51+
gArgs.AddArg("-stdinrpcpass", strprintf(_("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);
5552
}
5653

5754
//////////////////////////////////////////////////////////////////////////////
@@ -82,6 +79,7 @@ static int AppInitRPC(int argc, char* argv[])
8279
//
8380
// Parameters
8481
//
82+
SetupCliArgs();
8583
gArgs.ParseParameters(argc, argv);
8684
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
8785
std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n";
@@ -92,7 +90,7 @@ static int AppInitRPC(int argc, char* argv[])
9290
" bitcoin-cli [options] help " + _("List commands") + "\n" +
9391
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
9492

95-
strUsage += "\n" + HelpMessageCli();
93+
strUsage += "\n" + gArgs.GetHelpMessage();
9694
}
9795

9896
fprintf(stdout, "%s", strUsage.c_str());

src/bitcoin-tx.cpp

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,41 @@ static bool fCreateBlank;
3131
static std::map<std::string,UniValue> registers;
3232
static const int CONTINUE_EXECUTION=-1;
3333

34+
static void SetupBitcoinTxArgs()
35+
{
36+
gArgs.AddArg("-?", _("This help message"), false, OptionsCategory::OPTIONS);
37+
gArgs.AddArg("-create", _("Create new, empty TX."), false, OptionsCategory::OPTIONS);
38+
gArgs.AddArg("-json", _("Select JSON output"), false, OptionsCategory::OPTIONS);
39+
gArgs.AddArg("-txid", _("Output only the hex-encoded transaction id of the resultant transaction."), false, OptionsCategory::OPTIONS);
40+
SetupChainParamsBaseOptions();
41+
42+
gArgs.AddArg("delin=N", _("Delete input N from TX"), false, OptionsCategory::COMMANDS);
43+
gArgs.AddArg("delout=N", _("Delete output N from TX"), false, OptionsCategory::COMMANDS);
44+
gArgs.AddArg("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX"), false, OptionsCategory::COMMANDS);
45+
gArgs.AddArg("locktime=N", _("Set TX lock time to N"), false, OptionsCategory::COMMANDS);
46+
gArgs.AddArg("nversion=N", _("Set TX version to N"), false, OptionsCategory::COMMANDS);
47+
gArgs.AddArg("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"), false, OptionsCategory::COMMANDS);
48+
gArgs.AddArg("outdata=[VALUE:]DATA", _("Add data-based output to TX"), false, OptionsCategory::COMMANDS);
49+
gArgs.AddArg("outmultisig=VALUE:REQUIRED:PUBKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]", _("Add Pay To n-of-m Multi-sig output to TX. n = REQUIRED, m = PUBKEYS") + ". " +
50+
_("Optionally add the \"W\" flag to produce a pay-to-witness-script-hash output") + ". " +
51+
_("Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash."), false, OptionsCategory::COMMANDS);
52+
gArgs.AddArg("outpubkey=VALUE:PUBKEY[:FLAGS]", _("Add pay-to-pubkey output to TX") + ". " +
53+
_("Optionally add the \"W\" flag to produce a pay-to-witness-pubkey-hash output") + ". " +
54+
_("Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash."), false, OptionsCategory::COMMANDS);
55+
gArgs.AddArg("outscript=VALUE:SCRIPT[:FLAGS]", _("Add raw script output to TX") + ". " +
56+
_("Optionally add the \"W\" flag to produce a pay-to-witness-script-hash output") + ". " +
57+
_("Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash."), false, OptionsCategory::COMMANDS);
58+
gArgs.AddArg("replaceable(=N)", _("Set RBF opt-in sequence number for input N (if not provided, opt-in all available inputs)"), false, OptionsCategory::COMMANDS);
59+
gArgs.AddArg("sign=SIGHASH-FLAGS", _("Add zero or more signatures to transaction") + ". " +
60+
_("This command requires JSON registers:") +
61+
_("prevtxs=JSON object") + ", " +
62+
_("privatekeys=JSON object") + ". " +
63+
_("See signrawtransaction docs for format of sighash flags, JSON objects."), false, OptionsCategory::COMMANDS);
64+
65+
gArgs.AddArg("load=NAME:FILENAME", _("Load JSON file FILENAME into register NAME"), false, OptionsCategory::REGISTER_COMMANDS);
66+
gArgs.AddArg("set=NAME:JSON-STRING", _("Set register NAME to given JSON-STRING"), false, OptionsCategory::REGISTER_COMMANDS);
67+
}
68+
3469
//
3570
// This function returns either one of EXIT_ codes when it's expected to stop the process or
3671
// CONTINUE_EXECUTION when it's expected to continue further.
@@ -40,6 +75,7 @@ static int AppInitRawTx(int argc, char* argv[])
4075
//
4176
// Parameters
4277
//
78+
SetupBitcoinTxArgs();
4379
gArgs.ParseParameters(argc, argv);
4480

4581
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
@@ -59,48 +95,10 @@ static int AppInitRawTx(int argc, char* argv[])
5995
" bitcoin-tx [options] <hex-tx> [commands] " + _("Update hex-encoded bitcoin transaction") + "\n" +
6096
" bitcoin-tx [options] -create [commands] " + _("Create hex-encoded bitcoin transaction") + "\n" +
6197
"\n";
98+
strUsage += gArgs.GetHelpMessage();
6299

63100
fprintf(stdout, "%s", strUsage.c_str());
64101

65-
strUsage = HelpMessageGroup(_("Options:"));
66-
strUsage += HelpMessageOpt("-?", _("This help message"));
67-
strUsage += HelpMessageOpt("-create", _("Create new, empty TX."));
68-
strUsage += HelpMessageOpt("-json", _("Select JSON output"));
69-
strUsage += HelpMessageOpt("-txid", _("Output only the hex-encoded transaction id of the resultant transaction."));
70-
AppendParamsHelpMessages(strUsage);
71-
72-
fprintf(stdout, "%s", strUsage.c_str());
73-
74-
strUsage = HelpMessageGroup(_("Commands:"));
75-
strUsage += HelpMessageOpt("delin=N", _("Delete input N from TX"));
76-
strUsage += HelpMessageOpt("delout=N", _("Delete output N from TX"));
77-
strUsage += HelpMessageOpt("in=TXID:VOUT(:SEQUENCE_NUMBER)", _("Add input to TX"));
78-
strUsage += HelpMessageOpt("locktime=N", _("Set TX lock time to N"));
79-
strUsage += HelpMessageOpt("nversion=N", _("Set TX version to N"));
80-
strUsage += HelpMessageOpt("outaddr=VALUE:ADDRESS", _("Add address-based output to TX"));
81-
strUsage += HelpMessageOpt("outdata=[VALUE:]DATA", _("Add data-based output to TX"));
82-
strUsage += HelpMessageOpt("outmultisig=VALUE:REQUIRED:PUBKEYS:PUBKEY1:PUBKEY2:....[:FLAGS]", _("Add Pay To n-of-m Multi-sig output to TX. n = REQUIRED, m = PUBKEYS") + ". " +
83-
_("Optionally add the \"W\" flag to produce a pay-to-witness-script-hash output") + ". " +
84-
_("Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash."));
85-
strUsage += HelpMessageOpt("outpubkey=VALUE:PUBKEY[:FLAGS]", _("Add pay-to-pubkey output to TX") + ". " +
86-
_("Optionally add the \"W\" flag to produce a pay-to-witness-pubkey-hash output") + ". " +
87-
_("Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash."));
88-
strUsage += HelpMessageOpt("outscript=VALUE:SCRIPT[:FLAGS]", _("Add raw script output to TX") + ". " +
89-
_("Optionally add the \"W\" flag to produce a pay-to-witness-script-hash output") + ". " +
90-
_("Optionally add the \"S\" flag to wrap the output in a pay-to-script-hash."));
91-
strUsage += HelpMessageOpt("replaceable(=N)", _("Set RBF opt-in sequence number for input N (if not provided, opt-in all available inputs)"));
92-
strUsage += HelpMessageOpt("sign=SIGHASH-FLAGS", _("Add zero or more signatures to transaction") + ". " +
93-
_("This command requires JSON registers:") +
94-
_("prevtxs=JSON object") + ", " +
95-
_("privatekeys=JSON object") + ". " +
96-
_("See signrawtransaction docs for format of sighash flags, JSON objects."));
97-
fprintf(stdout, "%s", strUsage.c_str());
98-
99-
strUsage = HelpMessageGroup(_("Register Commands:"));
100-
strUsage += HelpMessageOpt("load=NAME:FILENAME", _("Load JSON file FILENAME into register NAME"));
101-
strUsage += HelpMessageOpt("set=NAME:JSON-STRING", _("Set register NAME to given JSON-STRING"));
102-
fprintf(stdout, "%s", strUsage.c_str());
103-
104102
if (argc < 2) {
105103
fprintf(stderr, "Error: too few parameters\n");
106104
return EXIT_FAILURE;

src/bitcoind.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ static bool AppInit(int argc, char* argv[])
6161
// Parameters
6262
//
6363
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
64+
SetupServerArgs();
65+
#if HAVE_DECL_DAEMON
66+
gArgs.AddArg("-daemon", _("Run in the background as a daemon and accept commands"), false, OptionsCategory::OPTIONS);
67+
#endif
6468
gArgs.ParseParameters(argc, argv);
6569

6670
// Process help and version before taking care about datadir
@@ -76,7 +80,7 @@ static bool AppInit(int argc, char* argv[])
7680
strUsage += "\n" + _("Usage:") + "\n" +
7781
" bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";
7882

79-
strUsage += "\n" + HelpMessage(HelpMessageMode::BITCOIND);
83+
strUsage += "\n" + gArgs.GetHelpMessage();
8084
}
8185

8286
fprintf(stdout, "%s", strUsage.c_str());

src/chainparamsbase.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@ const std::string CBaseChainParams::MAIN = "main";
1414
const std::string CBaseChainParams::TESTNET = "test";
1515
const std::string CBaseChainParams::REGTEST = "regtest";
1616

17-
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
17+
void SetupChainParamsBaseOptions()
1818
{
19-
strUsage += HelpMessageGroup(_("Chain selection options:"));
20-
if (debugHelp) {
21-
strUsage += HelpMessageOpt("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
22-
"This is intended for regression testing tools and app development.");
23-
}
24-
strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
19+
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "
20+
"This is intended for regression testing tools and app development.", true, OptionsCategory::CHAINPARAMS);
21+
gArgs.AddArg("-testnet", _("Use the test chain"), false, OptionsCategory::CHAINPARAMS);
2522
}
2623

2724
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;

src/chainparamsbase.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ class CBaseChainParams
4040
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain);
4141

4242
/**
43-
* Append the help messages for the chainparams options to the
44-
* parameter string.
43+
*Set the arguments for chainparams
4544
*/
46-
void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp=true);
45+
void SetupChainParamsBaseOptions();
4746

4847
/**
4948
* Return the currently selected parameters. This won't change after app

0 commit comments

Comments
 (0)