Skip to content

Commit b386970

Browse files
committed
[moveonly] Extract HelpRequested to dry up the help options testing
This ensures consistency across interfaces and makes the version handling more clear.
1 parent c564424 commit b386970

File tree

7 files changed

+14
-9
lines changed

7 files changed

+14
-9
lines changed

src/bench/bench_bitcoin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ main(int argc, char** argv)
2727
{
2828
gArgs.ParseParameters(argc, argv);
2929

30-
if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help")) {
30+
if (HelpRequested(gArgs)) {
3131
std::cout << HelpMessageGroup(_("Options:"))
3232
<< HelpMessageOpt("-?", _("Print this help message and exit"))
3333
<< HelpMessageOpt("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter"))

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ static int AppInitRPC(int argc, char* argv[])
8282
// Parameters
8383
//
8484
gArgs.ParseParameters(argc, argv);
85-
if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) {
85+
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
8686
std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n";
8787
if (!gArgs.IsArgSet("-version")) {
8888
strUsage += "\n" + _("Usage:") + "\n" +

src/bitcoin-tx.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ static int AppInitRawTx(int argc, char* argv[])
5151

5252
fCreateBlank = gArgs.GetBoolArg("-create", false);
5353

54-
if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help"))
55-
{
54+
if (argc < 2 || HelpRequested(gArgs)) {
5655
// First part of help message is specific to this utility
5756
std::string strUsage = strprintf(_("%s bitcoin-tx utility version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n\n" +
5857
_("Usage:") + "\n" +

src/bitcoind.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ bool AppInit(int argc, char* argv[])
7676
gArgs.ParseParameters(argc, argv);
7777

7878
// Process help and version before taking care about datadir
79-
if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version"))
80-
{
79+
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
8180
std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";
8281

8382
if (gArgs.IsArgSet("-version"))

src/qt/bitcoin.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,7 @@ int main(int argc, char *argv[])
613613

614614
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
615615
// but before showing splash screen.
616-
if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version"))
617-
{
616+
if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
618617
HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version"));
619618
help.showOrPrint();
620619
return EXIT_SUCCESS;

src/util.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,10 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV
584584
mapMultiArgs[strArg] = {strValue};
585585
}
586586

587-
587+
bool HelpRequested(const ArgsManager& args)
588+
{
589+
return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help");
590+
}
588591

589592
static const int screenWidth = 79;
590593
static const int optIndent = 2;

src/util.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ class ArgsManager
313313

314314
extern ArgsManager gArgs;
315315

316+
/**
317+
* @return true if help has been requested via a command-line arg
318+
*/
319+
bool HelpRequested(const ArgsManager& args);
320+
316321
/**
317322
* Format a string to be used as group of options in help messages
318323
*

0 commit comments

Comments
 (0)