Forcing the args manager be aware of this particular option smells wrong. Also, the boolean logic could be simplified to just show_debug || !arg.second.second.
For your convenience I have prepared a suitable diff that cleanly applies and simplifies the code:
<details><summary></summary>
diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp
index b08d4cd253..21d23f1985 100644
--- a/src/bench/bench_bitcoin.cpp
+++ b/src/bench/bench_bitcoin.cpp
@@ -42,7 +42,7 @@ main(int argc, char** argv)
gArgs.ParseParameters(argc, argv);
if (HelpRequested(gArgs)) {
- std::cout << gArgs.GetHelpMessage(HelpMessageMode::OTHER);
+ std::cout << gArgs.GetHelpMessage();
return 0;
}
diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
index 8cb886cabd..3f00a95c91 100644
--- a/src/bitcoin-cli.cpp
+++ b/src/bitcoin-cli.cpp
@@ -90,7 +90,7 @@ static int AppInitRPC(int argc, char* argv[])
" bitcoin-cli [options] help " + _("List commands") + "\n" +
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
- strUsage += "\n" + gArgs.GetHelpMessage(HelpMessageMode::OTHER);
+ strUsage += "\n" + gArgs.GetHelpMessage();
}
fprintf(stdout, "%s", strUsage.c_str());
diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
index 359bd7749a..13a4542c9c 100644
--- a/src/bitcoin-tx.cpp
+++ b/src/bitcoin-tx.cpp
@@ -95,7 +95,7 @@ static int AppInitRawTx(int argc, char* argv[])
" bitcoin-tx [options] <hex-tx> [commands] " + _("Update hex-encoded bitcoin transaction") + "\n" +
" bitcoin-tx [options] -create [commands] " + _("Create hex-encoded bitcoin transaction") + "\n" +
"\n";
- strUsage += gArgs.GetHelpMessage(HelpMessageMode::OTHER);
+ strUsage += gArgs.GetHelpMessage();
fprintf(stdout, "%s", strUsage.c_str());
diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
index 218a9e9f42..1a004ea4af 100644
--- a/src/bitcoind.cpp
+++ b/src/bitcoind.cpp
@@ -62,6 +62,9 @@ static bool AppInit(int argc, char* argv[])
//
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
SetupArgs();
+#if HAVE_DECL_DAEMON
+ gArgs.AddArg("-daemon", _("Run in the background as a daemon and accept commands"), false, OptionsCategory::OPTIONS);
+#endif
gArgs.ParseParameters(argc, argv);
// Process help and version before taking care about datadir
@@ -77,7 +80,7 @@ static bool AppInit(int argc, char* argv[])
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";
- strUsage += "\n" + gArgs.GetHelpMessage(HelpMessageMode::BITCOIND);
+ strUsage += "\n" + gArgs.GetHelpMessage();
}
fprintf(stdout, "%s", strUsage.c_str());
diff --git a/src/init.cpp b/src/init.cpp
index c371e13b21..cb00d58786 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -351,9 +351,6 @@ void SetupArgs()
gArgs.AddArg("-blockreconstructionextratxn=<n>", strprintf(_("Extra transactions to keep in memory for compact block reconstructions (default: %u)"), DEFAULT_BLOCK_RECONSTRUCTION_EXTRA_TXN), false, OptionsCategory::OPTIONS);
gArgs.AddArg("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY), true, OptionsCategory::OPTIONS);
gArgs.AddArg("-conf=<file>", strprintf(_("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
-#if HAVE_DECL_DAEMON
- gArgs.AddArg("-daemon", _("Run in the background as a daemon and accept commands"), false, OptionsCategory::OPTIONS);
-#endif
gArgs.AddArg("-datadir=<dir>", _("Specify data directory"), false, OptionsCategory::OPTIONS);
gArgs.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), true, OptionsCategory::OPTIONS);
gArgs.AddArg("-dbcache=<n>", strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache), false, OptionsCategory::OPTIONS);
diff --git a/src/interfaces/node.h b/src/interfaces/node.h
index a3f637db2d..44f53f7e78 100644
--- a/src/interfaces/node.h
+++ b/src/interfaces/node.h
@@ -7,7 +7,6 @@
#include <addrdb.h> // For banmap_t
#include <amount.h> // For CAmount
-#include <init.h> // For HelpMessageMode
#include <net.h> // For CConnman::NumConnections
#include <netaddress.h> // For Network
diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp
index 79be2823a3..993d7454d6 100644
--- a/src/qt/utilitydialog.cpp
+++ b/src/qt/utilitydialog.cpp
@@ -78,7 +78,7 @@ HelpMessageDialog::HelpMessageDialog(interfaces::Node& node, QWidget *parent, bo
cursor.insertText(header);
cursor.insertBlock();
- std::string strUsage = gArgs.GetHelpMessage(HelpMessageMode::OTHER);
+ std::string strUsage = gArgs.GetHelpMessage();
QString coreOptions = QString::fromStdString(strUsage);
text = version + "\n" + header + "\n" + coreOptions;
diff --git a/src/util.cpp b/src/util.cpp
index f59051e0e1..265f77f6ed 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -543,7 +543,7 @@ void ArgsManager::AddArg(const std::string& name, const std::string& help, const
m_available_args.emplace(key, std::pair<std::string, bool>(help, debug_only));
}
-std::string ArgsManager::GetHelpMessage(HelpMessageMode mode)
+std::string ArgsManager::GetHelpMessage()
{
const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
@@ -578,8 +578,7 @@ std::string ArgsManager::GetHelpMessage(HelpMessageMode mode)
else if (last_cat == OptionsCategory::REGISTER_COMMANDS)
usage += HelpMessageGroup(_("Register Commands:"));
}
- if ((!arg.second.second || (show_debug && arg.second.second)) &&
- (arg.first.second != "-daemon" || (arg.first.second == "-daemon" && mode == HelpMessageMode::BITCOIND))) {
+ if (show_debug||!arg.second.second) {
usage += HelpMessageOpt(arg.first.second, arg.second.first);
}
}
diff --git a/src/util.h b/src/util.h
index f36a9b254a..2c8fbfa312 100644
--- a/src/util.h
+++ b/src/util.h
@@ -135,12 +135,6 @@ enum class OptionsCategory
REGISTER_COMMANDS
};
-/** The help message mode determines what help message to show */
-enum class HelpMessageMode {
- BITCOIND,
- OTHER
-};
-
class ArgsManager
{
protected:
@@ -262,7 +256,7 @@ public:
/**
* Get the help string
*/
- std::string GetHelpMessage(HelpMessageMode mode);
+ std::string GetHelpMessage();
};
extern ArgsManager gArgs;
</details>