Merge #12846: [moveonly] Extract HelpRequested to dry up the help options testing

b386970d07 [moveonly] Extract HelpRequested to dry up the help options testing (Ben Woosley)

Pull request description:

  This ensures consistency across interfaces and makes the version handling more clear.

Tree-SHA512: d3f46d34dae6cf98902b0bbb279ada65c3215a25f69e5ff98b88e68f37a6b027ded265d15c12303998e31b390aa30fdb689455c61c983ab4b7527cbce8f4ec61
This commit is contained in:
MarcoFalke 2018-04-03 11:51:48 -04:00
commit ad960f5771
No known key found for this signature in database
GPG key ID: D2EA4850E7528B25
7 changed files with 14 additions and 9 deletions

View file

@ -27,7 +27,7 @@ main(int argc, char** argv)
{ {
gArgs.ParseParameters(argc, argv); gArgs.ParseParameters(argc, argv);
if (gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help")) { if (HelpRequested(gArgs)) {
std::cout << HelpMessageGroup(_("Options:")) std::cout << HelpMessageGroup(_("Options:"))
<< HelpMessageOpt("-?", _("Print this help message and exit")) << HelpMessageOpt("-?", _("Print this help message and exit"))
<< HelpMessageOpt("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter")) << HelpMessageOpt("-list", _("List benchmarks without executing them. Can be combined with -scaling and -filter"))

View file

@ -82,7 +82,7 @@ static int AppInitRPC(int argc, char* argv[])
// Parameters // Parameters
// //
gArgs.ParseParameters(argc, argv); 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"; std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n";
if (!gArgs.IsArgSet("-version")) { if (!gArgs.IsArgSet("-version")) {
strUsage += "\n" + _("Usage:") + "\n" + strUsage += "\n" + _("Usage:") + "\n" +

View file

@ -51,8 +51,7 @@ static int AppInitRawTx(int argc, char* argv[])
fCreateBlank = gArgs.GetBoolArg("-create", false); 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 // First part of help message is specific to this utility
std::string strUsage = strprintf(_("%s bitcoin-tx utility version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n\n" + std::string strUsage = strprintf(_("%s bitcoin-tx utility version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n\n" +
_("Usage:") + "\n" + _("Usage:") + "\n" +

View file

@ -76,8 +76,7 @@ bool AppInit(int argc, char* argv[])
gArgs.ParseParameters(argc, argv); gArgs.ParseParameters(argc, argv);
// Process help and version before taking care about datadir // 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"; std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";
if (gArgs.IsArgSet("-version")) if (gArgs.IsArgSet("-version"))

View file

@ -613,8 +613,7 @@ int main(int argc, char *argv[])
// Show help message immediately after parsing command-line options (for "-lang") and setting locale, // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
// but before showing splash screen. // 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")); HelpMessageDialog help(nullptr, gArgs.IsArgSet("-version"));
help.showOrPrint(); help.showOrPrint();
return EXIT_SUCCESS; return EXIT_SUCCESS;

View file

@ -584,7 +584,10 @@ void ArgsManager::ForceSetArg(const std::string& strArg, const std::string& strV
mapMultiArgs[strArg] = {strValue}; 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 screenWidth = 79;
static const int optIndent = 2; static const int optIndent = 2;

View file

@ -313,6 +313,11 @@ private:
extern ArgsManager gArgs; 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 * Format a string to be used as group of options in help messages
* *