From b386970d0750e368d6adc5d0c010ead329b5c7c1 Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Fri, 30 Mar 2018 13:47:36 -0700 Subject: [PATCH] [moveonly] Extract HelpRequested to dry up the help options testing This ensures consistency across interfaces and makes the version handling more clear. --- src/bench/bench_bitcoin.cpp | 2 +- src/bitcoin-cli.cpp | 2 +- src/bitcoin-tx.cpp | 3 +-- src/bitcoind.cpp | 3 +-- src/qt/bitcoin.cpp | 3 +-- src/util.cpp | 5 ++++- src/util.h | 5 +++++ 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index fc92a46c0..1d8788352 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -27,7 +27,7 @@ main(int argc, char** argv) { gArgs.ParseParameters(argc, argv); - if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help")) { + if (HelpRequested(gArgs)) { std::cout << HelpMessageGroup(_("Options:")) << HelpMessageOpt("-?", _("Print this help message and exit")) << HelpMessageOpt("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter")) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 8bdc21099..263520ee4 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -82,7 +82,7 @@ static int AppInitRPC(int argc, char* argv[]) // Parameters // gArgs.ParseParameters(argc, argv); - if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) { + if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n"; if (!gArgs.IsArgSet("-version")) { strUsage += "\n" + _("Usage:") + "\n" + diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 8218e883a..76a6f9489 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -51,8 +51,7 @@ static int AppInitRawTx(int argc, char* argv[]) fCreateBlank = gArgs.GetBoolArg("-create", false); - if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help")) - { + if (argc < 2 || HelpRequested(gArgs)) { // First part of help message is specific to this utility std::string strUsage = strprintf(_("%s bitcoin-tx utility version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n\n" + _("Usage:") + "\n" + diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp index df7fad89c..58518d611 100644 --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -76,8 +76,7 @@ bool AppInit(int argc, char* argv[]) gArgs.ParseParameters(argc, argv); // Process help and version before taking care about datadir - if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) - { + if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n"; if (gArgs.IsArgSet("-version")) diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index f853c0461..140e56123 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -613,8 +613,7 @@ int main(int argc, char *argv[]) // Show help message immediately after parsing command-line options (for "-lang") and setting locale, // but before showing splash screen. - if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) - { + if (HelpRequested(gArgs) || gArgs.IsArgSet("-version")) { HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version")); help.showOrPrint(); return EXIT_SUCCESS; diff --git a/src/util.cpp b/src/util.cpp index 490897899..46054f502 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -584,7 +584,10 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV mapMultiArgs[strArg] = {strValue}; } - +bool HelpRequested(const ArgsManager& args) +{ + return args.IsArgSet("-?") || args.IsArgSet("-h") || args.IsArgSet("-help"); +} static const int screenWidth = 79; static const int optIndent = 2; diff --git a/src/util.h b/src/util.h index 4c473c935..17881ff3b 100644 --- a/src/util.h +++ b/src/util.h @@ -313,6 +313,11 @@ private: extern ArgsManager gArgs; +/** + * @return true if help has been requested via a command-line arg + */ +bool HelpRequested(const ArgsManager& args); + /** * Format a string to be used as group of options in help messages *