dogecoin/src/bitcoin-cli.cpp
Wladimir J. van der Laan 96b733e996 Add -version option to get just the version
Adds a `-version` or `--version` option to print just the version
of the program for bitcoind, bitcoin-cli and bitcoin-qt.

Also make it that `-help` can be used to display the help (as well as
existing `--help`). Up to now, `-help` was the only option that didn't
work with either one or two dashes.
2014-06-11 14:22:50 +02:00

90 lines
2.7 KiB
C++

// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "util.h"
#include "init.h"
#include "rpcclient.h"
#include "rpcprotocol.h"
#include "ui_interface.h" /* for _(...) */
#include "chainparams.h"
#include <boost/filesystem/operations.hpp>
//////////////////////////////////////////////////////////////////////////////
//
// Start
//
static bool AppInitRPC(int argc, char* argv[])
{
//
// Parameters
//
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());
return false;
}
try {
ReadConfigFile(mapArgs, mapMultiArgs);
} catch(std::exception &e) {
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
}
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
if (!SelectParamsFromCommandLine()) {
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(true);
}
fprintf(stdout, "%s", strUsage.c_str());
return false;
}
return true;
}
int main(int argc, char* argv[])
{
SetupEnvironment();
try
{
if(!AppInitRPC(argc, argv))
return abs(RPC_MISC_ERROR);
}
catch (std::exception& e) {
PrintExceptionContinue(&e, "AppInitRPC()");
return abs(RPC_MISC_ERROR);
} catch (...) {
PrintExceptionContinue(NULL, "AppInitRPC()");
return abs(RPC_MISC_ERROR);
}
int ret = abs(RPC_MISC_ERROR);
try
{
ret = CommandLineRPC(argc, argv);
}
catch (std::exception& e) {
PrintExceptionContinue(&e, "CommandLineRPC()");
} catch (...) {
PrintExceptionContinue(NULL, "CommandLineRPC()");
}
return ret;
}