Skip to content

Commit ac0b239

Browse files
committed
Merge pull request #5351
3d0a1ce Process help and version arguments before datadir. (Pavel Janík)
2 parents 397b901 + 3d0a1ce commit ac0b239

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

src/bitcoin-cli.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ static bool AppInitRPC(int argc, char* argv[])
6666
// Parameters
6767
//
6868
ParseParameters(argc, argv);
69+
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) {
70+
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
71+
if (!mapArgs.count("-version")) {
72+
strUsage += "\n" + _("Usage:") + "\n" +
73+
" bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
74+
" bitcoin-cli [options] help " + _("List commands") + "\n" +
75+
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
76+
77+
strUsage += "\n" + HelpMessageCli();
78+
}
79+
80+
fprintf(stdout, "%s", strUsage.c_str());
81+
return false;
82+
}
6983
if (!boost::filesystem::is_directory(GetDataDir(false))) {
7084
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
7185
return false;
@@ -81,20 +95,6 @@ static bool AppInitRPC(int argc, char* argv[])
8195
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
8296
return false;
8397
}
84-
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) {
85-
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
86-
if (!mapArgs.count("-version")) {
87-
strUsage += "\n" + _("Usage:") + "\n" +
88-
" bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
89-
" bitcoin-cli [options] help " + _("List commands") + "\n" +
90-
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
91-
92-
strUsage += "\n" + HelpMessageCli();
93-
}
94-
95-
fprintf(stdout, "%s", strUsage.c_str());
96-
return false;
97-
}
9898
return true;
9999
}
100100

src/bitcoind.cpp

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,36 @@ bool AppInit(int argc, char* argv[])
5959
boost::thread* detectShutdownThread = NULL;
6060

6161
bool fRet = false;
62+
63+
//
64+
// Parameters
65+
//
66+
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
67+
ParseParameters(argc, argv);
68+
69+
// Process help and version before taking care about datadir
70+
if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
71+
{
72+
std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
73+
74+
if (mapArgs.count("-version"))
75+
{
76+
strUsage += LicenseInfo();
77+
}
78+
else
79+
{
80+
strUsage += "\n" + _("Usage:") + "\n" +
81+
" bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n";
82+
83+
strUsage += "\n" + HelpMessage(HMM_BITCOIND);
84+
}
85+
86+
fprintf(stdout, "%s", strUsage.c_str());
87+
return false;
88+
}
89+
6290
try
6391
{
64-
//
65-
// Parameters
66-
//
67-
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
68-
ParseParameters(argc, argv);
6992
if (!boost::filesystem::is_directory(GetDataDir(false)))
7093
{
7194
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
@@ -84,26 +107,6 @@ bool AppInit(int argc, char* argv[])
84107
return false;
85108
}
86109

87-
if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
88-
{
89-
std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
90-
91-
if (mapArgs.count("-version"))
92-
{
93-
strUsage += LicenseInfo();
94-
}
95-
else
96-
{
97-
strUsage += "\n" + _("Usage:") + "\n" +
98-
" bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n";
99-
100-
strUsage += "\n" + HelpMessage(HMM_BITCOIND);
101-
}
102-
103-
fprintf(stdout, "%s", strUsage.c_str());
104-
return false;
105-
}
106-
107110
// Command-line RPC
108111
bool fCommandLine = false;
109112
for (int i = 1; i < argc; i++)

0 commit comments

Comments
 (0)