From a99999cc04c2e7d79bb841fd954c84e985ed3b88 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Wed, 6 Feb 2019 13:57:52 -0500 Subject: [PATCH] util: Add SetupHelpOptions() --- doc/man/bitcoin-cli.1 | 2 +- doc/man/bitcoin-tx.1 | 2 +- doc/man/bitcoin-wallet.1 | 2 +- src/bench/bench_bitcoin.cpp | 7 ++----- src/bitcoin-cli.cpp | 7 ++----- src/bitcoin-tx.cpp | 7 ++----- src/bitcoin-wallet.cpp | 6 +----- src/init.cpp | 9 ++++----- src/util/system.cpp | 6 ++++++ src/util/system.h | 3 +++ 10 files changed, 23 insertions(+), 28 deletions(-) diff --git a/doc/man/bitcoin-cli.1 b/doc/man/bitcoin-cli.1 index 355b4d3cc2b..95c1d24dff0 100644 --- a/doc/man/bitcoin-cli.1 +++ b/doc/man/bitcoin-cli.1 @@ -20,7 +20,7 @@ Bitcoin Core RPC client version v0.17.99.0 .HP \-? .IP -This help message +Print this help message and exit .HP \fB\-conf=\fR .IP diff --git a/doc/man/bitcoin-tx.1 b/doc/man/bitcoin-tx.1 index c5d39857637..6b6071d9b74 100644 --- a/doc/man/bitcoin-tx.1 +++ b/doc/man/bitcoin-tx.1 @@ -14,7 +14,7 @@ Bitcoin Core bitcoin\-tx utility version v0.17.99.0 .HP \-? .IP -This help message +Print this help message and exit .HP \fB\-create\fR .IP diff --git a/doc/man/bitcoin-wallet.1 b/doc/man/bitcoin-wallet.1 index 3c4849cca75..1cb8cdebcd3 100644 --- a/doc/man/bitcoin-wallet.1 +++ b/doc/man/bitcoin-wallet.1 @@ -15,7 +15,7 @@ bitcoin\-wallet [options] .HP \-? .IP -This help message +Print this help message and exit .HP \fB\-datadir=\fR .IP diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp index b804a844788..d67b2c5bc78 100644 --- a/src/bench/bench_bitcoin.cpp +++ b/src/bench/bench_bitcoin.cpp @@ -24,7 +24,8 @@ static const int64_t DEFAULT_PLOT_HEIGHT = 768; static void SetupBenchArgs() { - gArgs.AddArg("-?", "Print this help message and exit", false, OptionsCategory::OPTIONS); + SetupHelpOptions(gArgs); + gArgs.AddArg("-list", "List benchmarks without executing them. Can be combined with -scaling and -filter", false, OptionsCategory::OPTIONS); gArgs.AddArg("-evals=", strprintf("Number of measurement evaluations to perform. (default: %u)", DEFAULT_BENCH_EVALUATIONS), false, OptionsCategory::OPTIONS); gArgs.AddArg("-filter=", strprintf("Regular expression filter to select benchmark by name (default: %s)", DEFAULT_BENCH_FILTER), false, OptionsCategory::OPTIONS); @@ -33,10 +34,6 @@ static void SetupBenchArgs() gArgs.AddArg("-plot-plotlyurl=", strprintf("URL to use for plotly.js (default: %s)", DEFAULT_PLOT_PLOTLYURL), false, OptionsCategory::OPTIONS); gArgs.AddArg("-plot-width=", strprintf("Plot width in pixel (default: %u)", DEFAULT_PLOT_WIDTH), false, OptionsCategory::OPTIONS); gArgs.AddArg("-plot-height=", strprintf("Plot height in pixel (default: %u)", DEFAULT_PLOT_HEIGHT), false, OptionsCategory::OPTIONS); - - // Hidden - gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN); - gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN); } static fs::path SetDataDir() diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 7cdf61ad355..b0e1f67d939 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -34,11 +34,12 @@ static const int CONTINUE_EXECUTION=-1; static void SetupCliArgs() { + SetupHelpOptions(gArgs); + const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN); const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET); const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST); - gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS); gArgs.AddArg("-version", "Print version and exit", false, OptionsCategory::OPTIONS); gArgs.AddArg("-conf=", strprintf("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)", BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS); gArgs.AddArg("-datadir=", "Specify data directory", false, OptionsCategory::OPTIONS); @@ -55,10 +56,6 @@ static void SetupCliArgs() gArgs.AddArg("-rpcwallet=", "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/", 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); - - // Hidden - gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN); - gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN); } /** libevent event log callback */ diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp index 9d1309cde3d..4be89aab6cf 100644 --- a/src/bitcoin-tx.cpp +++ b/src/bitcoin-tx.cpp @@ -35,7 +35,8 @@ const std::function 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); @@ -66,10 +67,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); } // diff --git a/src/bitcoin-wallet.cpp b/src/bitcoin-wallet.cpp index 11caa0dc6c7..32a539aac66 100644 --- a/src/bitcoin-wallet.cpp +++ b/src/bitcoin-wallet.cpp @@ -20,9 +20,9 @@ const std::function G_TRANSLATION_FUN = nullptr; static void SetupWalletToolArgs() { + SetupHelpOptions(gArgs); SetupChainParamsBaseOptions(); - gArgs.AddArg("-?", "This help message", false, OptionsCategory::OPTIONS); gArgs.AddArg("-datadir=", "Specify data directory", false, OptionsCategory::OPTIONS); gArgs.AddArg("-wallet=", "Specify wallet name", false, OptionsCategory::OPTIONS); gArgs.AddArg("-debug=", "Output debugging information (default: 0).", false, OptionsCategory::DEBUG_TEST); @@ -30,10 +30,6 @@ static void SetupWalletToolArgs() gArgs.AddArg("info", "Get wallet info", false, OptionsCategory::COMMANDS); gArgs.AddArg("create", "Create new wallet file", false, OptionsCategory::COMMANDS); - - // Hidden - gArgs.AddArg("-h", "", false, OptionsCategory::HIDDEN); - gArgs.AddArg("-help", "", false, OptionsCategory::HIDDEN); } static bool WalletAppInit(int argc, char* argv[]) diff --git a/src/init.cpp b/src/init.cpp index 8fcf94b49ba..09e28f4006d 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -326,6 +326,9 @@ static void OnRPCStopped() 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 regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST); @@ -334,14 +337,11 @@ void SetupServerArgs() const auto regtestChainParams = CreateChainParams(CBaseChainParams::REGTEST); // Hidden Options - std::vector hidden_args = {"-h", "-help", + std::vector hidden_args = { "-dbcrashratio", "-forcecompactdb", // GUI args. These will be overwritten by SetupUIArgs for the GUI "-allowselfsignedrootcertificates", "-choosedatadir", "-lang=", "-min", "-resetguisettings", "-rootcertificates=", "-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=", "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=", 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() gArgs.AddArg("-debug=", "Output debugging information (default: -nodebug, supplying is optional). " "If is not supplied or if = 1, output all debugging information. can be: " + ListLogCategories() + ".", false, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-debugexclude=", 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("-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("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), false, OptionsCategory::DEBUG_TEST); gArgs.AddArg("-logtimemicros", strprintf("Add microsecond precision to debug timestamps (default: %u)", DEFAULT_LOGTIMEMICROS), true, OptionsCategory::DEBUG_TEST); diff --git a/src/util/system.cpp b/src/util/system.cpp index bb9fcab59e8..27ed24d0122 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -635,6 +635,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; diff --git a/src/util/system.h b/src/util/system.h index 17723d427da..54d4cf2e58b 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -295,6 +295,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 *