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:
0diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp
1index b08d4cd253..21d23f1985 100644
2--- a/src/bench/bench_bitcoin.cpp
3+++ b/src/bench/bench_bitcoin.cpp
4@@ -42,7 +42,7 @@ main(int argc, char** argv)
5 gArgs.ParseParameters(argc, argv);
6
7 if (HelpRequested(gArgs)) {
8- std::cout << gArgs.GetHelpMessage(HelpMessageMode::OTHER);
9+ std::cout << gArgs.GetHelpMessage();
10
11 return 0;
12 }
13diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp
14index 8cb886cabd..3f00a95c91 100644
15--- a/src/bitcoin-cli.cpp
16+++ b/src/bitcoin-cli.cpp
17@@ -90,7 +90,7 @@ static int AppInitRPC(int argc, char* argv[])
18 " bitcoin-cli [options] help " + _("List commands") + "\n" +
19 " bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
20
21- strUsage += "\n" + gArgs.GetHelpMessage(HelpMessageMode::OTHER);
22+ strUsage += "\n" + gArgs.GetHelpMessage();
23 }
24
25 fprintf(stdout, "%s", strUsage.c_str());
26diff --git a/src/bitcoin-tx.cpp b/src/bitcoin-tx.cpp
27index 359bd7749a..13a4542c9c 100644
28--- a/src/bitcoin-tx.cpp
29+++ b/src/bitcoin-tx.cpp
30@@ -95,7 +95,7 @@ static int AppInitRawTx(int argc, char* argv[])
31 " bitcoin-tx [options] <hex-tx> [commands] " + _("Update hex-encoded bitcoin transaction") + "\n" +
32 " bitcoin-tx [options] -create [commands] " + _("Create hex-encoded bitcoin transaction") + "\n" +
33 "\n";
34- strUsage += gArgs.GetHelpMessage(HelpMessageMode::OTHER);
35+ strUsage += gArgs.GetHelpMessage();
36
37 fprintf(stdout, "%s", strUsage.c_str());
38
39diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
40index 218a9e9f42..1a004ea4af 100644
41--- a/src/bitcoind.cpp
42+++ b/src/bitcoind.cpp
43@@ -62,6 +62,9 @@ static bool AppInit(int argc, char* argv[])
44 //
45 // If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
46 SetupArgs();
47+#if HAVE_DECL_DAEMON
48+ gArgs.AddArg("-daemon", _("Run in the background as a daemon and accept commands"), false, OptionsCategory::OPTIONS);
49+#endif
50 gArgs.ParseParameters(argc, argv);
51
52 // Process help and version before taking care about datadir
53@@ -77,7 +80,7 @@ static bool AppInit(int argc, char* argv[])
54 strUsage += "\n" + _("Usage:") + "\n" +
55 " bitcoind [options] " + strprintf(_("Start %s Daemon"), _(PACKAGE_NAME)) + "\n";
56
57- strUsage += "\n" + gArgs.GetHelpMessage(HelpMessageMode::BITCOIND);
58+ strUsage += "\n" + gArgs.GetHelpMessage();
59 }
60
61 fprintf(stdout, "%s", strUsage.c_str());
62diff --git a/src/init.cpp b/src/init.cpp
63index c371e13b21..cb00d58786 100644
64--- a/src/init.cpp
65+++ b/src/init.cpp
66@@ -351,9 +351,6 @@ void SetupArgs()
67 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);
68 gArgs.AddArg("-blocksonly", strprintf(_("Whether to operate in a blocks only mode (default: %u)"), DEFAULT_BLOCKSONLY), true, OptionsCategory::OPTIONS);
69 gArgs.AddArg("-conf=<file>", strprintf(_("Specify configuration file. Relative paths will be prefixed by datadir location. (default: %s)"), BITCOIN_CONF_FILENAME), false, OptionsCategory::OPTIONS);
70-#if HAVE_DECL_DAEMON
71- gArgs.AddArg("-daemon", _("Run in the background as a daemon and accept commands"), false, OptionsCategory::OPTIONS);
72-#endif
73 gArgs.AddArg("-datadir=<dir>", _("Specify data directory"), false, OptionsCategory::OPTIONS);
74 gArgs.AddArg("-dbbatchsize", strprintf("Maximum database write batch size in bytes (default: %u)", nDefaultDbBatchSize), true, OptionsCategory::OPTIONS);
75 gArgs.AddArg("-dbcache=<n>", strprintf(_("Set database cache size in megabytes (%d to %d, default: %d)"), nMinDbCache, nMaxDbCache, nDefaultDbCache), false, OptionsCategory::OPTIONS);
76diff --git a/src/interfaces/node.h b/src/interfaces/node.h
77index a3f637db2d..44f53f7e78 100644
78--- a/src/interfaces/node.h
79+++ b/src/interfaces/node.h
80@@ -7,7 +7,6 @@
81
82 #include <addrdb.h> // For banmap_t
83 #include <amount.h> // For CAmount
84-#include <init.h> // For HelpMessageMode
85 #include <net.h> // For CConnman::NumConnections
86 #include <netaddress.h> // For Network
87
88diff --git a/src/qt/utilitydialog.cpp b/src/qt/utilitydialog.cpp
89index 79be2823a3..993d7454d6 100644
90--- a/src/qt/utilitydialog.cpp
91+++ b/src/qt/utilitydialog.cpp
92@@ -78,7 +78,7 @@ HelpMessageDialog::HelpMessageDialog(interfaces::Node& node, QWidget *parent, bo
93 cursor.insertText(header);
94 cursor.insertBlock();
95
96- std::string strUsage = gArgs.GetHelpMessage(HelpMessageMode::OTHER);
97+ std::string strUsage = gArgs.GetHelpMessage();
98 QString coreOptions = QString::fromStdString(strUsage);
99 text = version + "\n" + header + "\n" + coreOptions;
100
101diff --git a/src/util.cpp b/src/util.cpp
102index f59051e0e1..265f77f6ed 100644
103--- a/src/util.cpp
104+++ b/src/util.cpp
105@@ -543,7 +543,7 @@ void ArgsManager::AddArg(const std::string& name, const std::string& help, const
106 m_available_args.emplace(key, std::pair<std::string, bool>(help, debug_only));
107 }
108
109-std::string ArgsManager::GetHelpMessage(HelpMessageMode mode)
110+std::string ArgsManager::GetHelpMessage()
111 {
112 const bool show_debug = gArgs.GetBoolArg("-help-debug", false);
113
114@@ -578,8 +578,7 @@ std::string ArgsManager::GetHelpMessage(HelpMessageMode mode)
115 else if (last_cat == OptionsCategory::REGISTER_COMMANDS)
116 usage += HelpMessageGroup(_("Register Commands:"));
117 }
118- if ((!arg.second.second || (show_debug && arg.second.second)) &&
119- (arg.first.second != "-daemon" || (arg.first.second == "-daemon" && mode == HelpMessageMode::BITCOIND))) {
120+ if (show_debug||!arg.second.second) {
121 usage += HelpMessageOpt(arg.first.second, arg.second.first);
122 }
123 }
124diff --git a/src/util.h b/src/util.h
125index f36a9b254a..2c8fbfa312 100644
126--- a/src/util.h
127+++ b/src/util.h
128@@ -135,12 +135,6 @@ enum class OptionsCategory
129 REGISTER_COMMANDS
130 };
131
132-/** The help message mode determines what help message to show */
133-enum class HelpMessageMode {
134- BITCOIND,
135- OTHER
136-};
137-
138 class ArgsManager
139 {
140 protected:
141@@ -262,7 +256,7 @@ public:
142 /**
143 * Get the help string
144 */
145- std::string GetHelpMessage(HelpMessageMode mode);
146+ std::string GetHelpMessage();
147 };
148
149 extern ArgsManager gArgs;