Skip to content

Commit

Permalink
Merge pull request #5351
Browse files Browse the repository at this point in the history
3d0a1ce Process help and version arguments before datadir. (Pavel Janík)
  • Loading branch information
laanwj committed Nov 25, 2014
2 parents 397b901 + 3d0a1ce commit ac0b239
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 39 deletions.
28 changes: 14 additions & 14 deletions src/bitcoin-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ static bool AppInitRPC(int argc, char* argv[])
// Parameters
//
ParseParameters(argc, argv);
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) {
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
if (!mapArgs.count("-version")) {
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
" bitcoin-cli [options] help " + _("List commands") + "\n" +
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";

strUsage += "\n" + HelpMessageCli();
}

fprintf(stdout, "%s", strUsage.c_str());
return false;
}
if (!boost::filesystem::is_directory(GetDataDir(false))) {
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
return false;
Expand All @@ -81,20 +95,6 @@ static bool AppInitRPC(int argc, char* argv[])
fprintf(stderr, "Error: Invalid combination of -regtest and -testnet.\n");
return false;
}
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version")) {
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
if (!mapArgs.count("-version")) {
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
" bitcoin-cli [options] help " + _("List commands") + "\n" +
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";

strUsage += "\n" + HelpMessageCli();
}

fprintf(stdout, "%s", strUsage.c_str());
return false;
}
return true;
}

Expand Down
53 changes: 28 additions & 25 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,36 @@ bool AppInit(int argc, char* argv[])
boost::thread* detectShutdownThread = NULL;

bool fRet = false;

//
// Parameters
//
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
ParseParameters(argc, argv);

// Process help and version before taking care about datadir
if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{
std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";

if (mapArgs.count("-version"))
{
strUsage += LicenseInfo();
}
else
{
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n";

strUsage += "\n" + HelpMessage(HMM_BITCOIND);
}

fprintf(stdout, "%s", strUsage.c_str());
return false;
}

try
{
//
// Parameters
//
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
ParseParameters(argc, argv);
if (!boost::filesystem::is_directory(GetDataDir(false)))
{
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", mapArgs["-datadir"].c_str());
Expand All @@ -84,26 +107,6 @@ bool AppInit(int argc, char* argv[])
return false;
}

if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{
std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";

if (mapArgs.count("-version"))
{
strUsage += LicenseInfo();
}
else
{
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n";

strUsage += "\n" + HelpMessage(HMM_BITCOIND);
}

fprintf(stdout, "%s", strUsage.c_str());
return false;
}

// Command-line RPC
bool fCommandLine = false;
for (int i = 1; i < argc; i++)
Expand Down

0 comments on commit ac0b239

Please sign in to comment.