Browse Source

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.
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
96b733e996
  1. 18
      src/bitcoin-cli.cpp
  2. 27
      src/bitcoind.cpp
  3. 4
      src/qt/bitcoin.cpp
  4. 2
      src/qt/bitcoingui.cpp
  5. 19
      src/qt/utilitydialog.cpp
  6. 5
      src/qt/utilitydialog.h

18
src/bitcoin-cli.cpp

@ -39,16 +39,18 @@ static bool AppInitRPC(int argc, char* argv[])
return false; return false;
} }
if (argc<2 || mapArgs.count("-?") || mapArgs.count("--help")) if (argc<2 || mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{ {
// First part of help message is specific to RPC client std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n";
std::string strUsage = _("Bitcoin Core RPC client version") + " " + FormatFullVersion() + "\n\n" + if (!mapArgs.count("-version"))
_("Usage:") + "\n" + {
" bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" + strUsage += "\n" + _("Usage:") + "\n" +
" bitcoin-cli [options] help " + _("List commands") + "\n" + " bitcoin-cli [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n"; " bitcoin-cli [options] help " + _("List commands") + "\n" +
" bitcoin-cli [options] help <command> " + _("Get help for a command") + "\n";
strUsage += "\n" + HelpMessageCli(true); strUsage += "\n" + HelpMessageCli(true);
}
fprintf(stdout, "%s", strUsage.c_str()); fprintf(stdout, "%s", strUsage.c_str());
return false; return false;

27
src/bitcoind.cpp

@ -83,19 +83,22 @@ bool AppInit(int argc, char* argv[])
return false; return false;
} }
if (mapArgs.count("-?") || mapArgs.count("--help")) if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{ {
// First part of help message is specific to bitcoind / RPC client std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n";
std::string strUsage = _("Bitcoin Core Daemon") + " " + _("version") + " " + FormatFullVersion() + "\n\n" +
_("Usage:") + "\n" + if (!mapArgs.count("-version"))
" bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n" + {
_("Usage (deprecated, use bitcoin-cli):") + "\n" + strUsage += "\n" + _("Usage:") + "\n" +
" bitcoind [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" + " bitcoind [options] " + _("Start Bitcoin Core Daemon") + "\n" +
" bitcoind [options] help " + _("List commands") + "\n" + _("Usage (deprecated, use bitcoin-cli):") + "\n" +
" bitcoind [options] help <command> " + _("Get help for a command") + "\n"; " bitcoind [options] <command> [params] " + _("Send command to Bitcoin Core") + "\n" +
" bitcoind [options] help " + _("List commands") + "\n" +
strUsage += "\n" + HelpMessage(HMM_BITCOIND); " bitcoind [options] help <command> " + _("Get help for a command") + "\n";
strUsage += "\n" + HelpMessageCli(false);
strUsage += "\n" + HelpMessage(HMM_BITCOIND);
strUsage += "\n" + HelpMessageCli(false);
}
fprintf(stdout, "%s", strUsage.c_str()); fprintf(stdout, "%s", strUsage.c_str());
return false; return false;

4
src/qt/bitcoin.cpp

@ -503,9 +503,9 @@ int main(int argc, char *argv[])
// Show help message immediately after parsing command-line options (for "-lang") and setting locale, // Show help message immediately after parsing command-line options (for "-lang") and setting locale,
// but before showing splash screen. // but before showing splash screen.
if (mapArgs.count("-?") || mapArgs.count("--help")) if (mapArgs.count("-?") || mapArgs.count("-help") || mapArgs.count("-version"))
{ {
HelpMessageDialog help(NULL); HelpMessageDialog help(NULL, mapArgs.count("-version"));
help.showOrPrint(); help.showOrPrint();
return 1; return 1;
} }

2
src/qt/bitcoingui.cpp

@ -556,7 +556,7 @@ void BitcoinGUI::aboutClicked()
void BitcoinGUI::showHelpMessageClicked() void BitcoinGUI::showHelpMessageClicked()
{ {
HelpMessageDialog *help = new HelpMessageDialog(this); HelpMessageDialog *help = new HelpMessageDialog(this, false);
help->setAttribute(Qt::WA_DeleteOnClose); help->setAttribute(Qt::WA_DeleteOnClose);
help->show(); help->show();
} }

19
src/qt/utilitydialog.cpp

@ -57,21 +57,20 @@ void AboutDialog::on_buttonBox_accepted()
} }
/** "Help message" dialog box */ /** "Help message" dialog box */
HelpMessageDialog::HelpMessageDialog(QWidget *parent) : HelpMessageDialog::HelpMessageDialog(QWidget *parent, bool versionOnly) :
QDialog(parent), QDialog(parent),
ui(new Ui::HelpMessageDialog) ui(new Ui::HelpMessageDialog)
{ {
ui->setupUi(this); ui->setupUi(this);
GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this); GUIUtil::restoreWindowGeometry("nHelpMessageDialogWindow", this->size(), this);
header = tr("Bitcoin Core") + " " + tr("version") + " " + QString version = tr("Bitcoin Core") + " " + tr("version") + " " + QString::fromStdString(FormatFullVersion());
QString::fromStdString(FormatFullVersion()) + "\n\n" + QString header = tr("Usage:") + "\n" +
tr("Usage:") + "\n" +
" bitcoin-qt [" + tr("command-line options") + "] " + "\n"; " bitcoin-qt [" + tr("command-line options") + "] " + "\n";
coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT)); QString coreOptions = QString::fromStdString(HelpMessage(HMM_BITCOIN_QT));
uiOptions = tr("UI options") + ":\n" + QString uiOptions = tr("UI options") + ":\n" +
" -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" + " -choosedatadir " + tr("Choose data directory on startup (default: 0)") + "\n" +
" -lang=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" + " -lang=<lang> " + tr("Set language, for example \"de_DE\" (default: system locale)") + "\n" +
" -min " + tr("Start minimized") + "\n" + " -min " + tr("Start minimized") + "\n" +
@ -81,7 +80,10 @@ HelpMessageDialog::HelpMessageDialog(QWidget *parent) :
ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont()); ui->helpMessageLabel->setFont(GUIUtil::bitcoinAddressFont());
// Set help message text // Set help message text
ui->helpMessageLabel->setText(header + "\n" + coreOptions + "\n" + uiOptions); if(versionOnly)
ui->helpMessageLabel->setText(version);
else
ui->helpMessageLabel->setText(version + "\n" + header + "\n" + coreOptions + "\n" + uiOptions);
} }
HelpMessageDialog::~HelpMessageDialog() HelpMessageDialog::~HelpMessageDialog()
@ -93,8 +95,7 @@ HelpMessageDialog::~HelpMessageDialog()
void HelpMessageDialog::printToConsole() void HelpMessageDialog::printToConsole()
{ {
// On other operating systems, the expected action is to print the message to the console. // On other operating systems, the expected action is to print the message to the console.
QString strUsage = header + "\n" + coreOptions + "\n" + uiOptions + "\n"; fprintf(stdout, "%s\n", qPrintable(ui->helpMessageLabel->text()));
fprintf(stdout, "%s", strUsage.toStdString().c_str());
} }
void HelpMessageDialog::showOrPrint() void HelpMessageDialog::showOrPrint()

5
src/qt/utilitydialog.h

@ -40,7 +40,7 @@ class HelpMessageDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit HelpMessageDialog(QWidget *parent); explicit HelpMessageDialog(QWidget *parent, bool versionOnly);
~HelpMessageDialog(); ~HelpMessageDialog();
void printToConsole(); void printToConsole();
@ -48,9 +48,6 @@ public:
private: private:
Ui::HelpMessageDialog *ui; Ui::HelpMessageDialog *ui;
QString header;
QString coreOptions;
QString uiOptions;
private slots: private slots:
void on_okButton_accepted(); void on_okButton_accepted();

Loading…
Cancel
Save