Repository: bitcoin/bitcoin
File: src/bitcoin-cli.cpp (C++)

Code before:
// Exception thrown on connection error.  This error is used to determine
// when to wait if -rpcwait is given.
//
class CConnectionFailed : public std::runtime_error
{
public:

    explicit inline CConnectionFailed(const std::string& msg) :
        std::runtime_error(msg)
    {}

};

//
// This function returns either one of EXIT_ codes when it's expected to stop the process or
// CONTINUE_EXECUTION when it's expected to continue further.
//
static int AppInitRPC(int argc, char* argv[])
{
    SetupCliArgs(gArgs);
    std::string error;
    if (!gArgs.ParseParameters(argc, argv, error)) {
        tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);
        return EXIT_FAILURE;
    }
    if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
        std::string strUsage = CLIENT_NAME " RPC client version " + FormatFullVersion() + "\n";

        if (gArgs.IsArgSet("-version")) {
            strUsage += FormatParagraph(LicenseInfo());
        } else {
            strUsage += "\n"
                "The bitcoin-cli utility provides a command line interface to interact with a " CLIENT_NAME " RPC server.\n"
                "\nIt can be used to query network information, manage wallets, create or broadcast transactions, and control the " CLIENT_NAME " server.\n"
                "\nUse the \"help\" command to list all commands. Use \"help <command>\" to show help for that command.\n"
                "The -named option allows you to specify parameters using the key=value format, eliminating the need to pass unused positional parameters.\n"
                "\n"
                "Usage: bitcoin-cli [options] <command> [params]\n"
                "or:    bitcoin-cli [options] -named <command> [name=value]...\n"
                "or:    bitcoin-cli [options] help\n"
                "or:    bitcoin-cli [options] help <command>\n"
                "\n";
            strUsage += "\n" + gArgs.GetHelpMessage();
        }

        tfm::format(std::cout, "%s", strUsage);
        if (argc < 2) {
            tfm::format(std::cerr, "Error: too few parameters\n");
            return EXIT_FAILURE;
        }
        return EXIT_SUCCESS;

Review comment (bug):
Again great catch. I noticed the difference in the output in master and this branch. 

```
➜  bitcoin git:(master) ✗ bitcoinclireg -noversion
Bitcoin Core RPC client version v28.99.0-65b194193661
Copyright (C) 2009-2024 The Bitcoin Core developers

Please contribute if you find Bitcoin Core useful. Visit
<https://bitcoincore.org/> for further information about the software.
The source code is available from <https://github.com/bitcoin/bitcoin>.

This is experimental software.
Distributed under the MIT software license, see the accompanying file COPYING
or <https://opensource.org/licenses/MIT>

➜  bitcoin git:(master) ✗ bitcoinclireg -noversion
error: too few parameters (need at least command)
```

Wondering now maybe we should disallow negation for `version` altogether? The output of `noversion` now is too few params and I fail to see any benefit in allowing this (maybe I'm missing something here). Might as well throw this error?

```
Negating of -version is meaningless and therefore forbidden
```

Code after:
// Exception thrown on connection error.  This error is used to determine
// when to wait if -rpcwait is given.
//
class CConnectionFailed : public std::runtime_error
{
public:

    explicit inline CConnectionFailed(const std::string& msg) :
        std::runtime_error(msg)
    {}

};

//
// This function returns either one of EXIT_ codes when it's expected to stop the process or
// CONTINUE_EXECUTION when it's expected to continue further.
//
static int AppInitRPC(int argc, char* argv[])
{
    SetupCliArgs(gArgs);
    std::string error;
    if (!gArgs.ParseParameters(argc, argv, error)) {
        tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);
        return EXIT_FAILURE;
    }
    if (argc < 2 || HelpRequested(gArgs) || gArgs.GetBoolArg("-version", false)) {
        std::string strUsage = CLIENT_NAME " RPC client version " + FormatFullVersion() + "\n";

        if (gArgs.GetBoolArg("-version", false)) {
            strUsage += FormatParagraph(LicenseInfo());
        } else {
            strUsage += "\n"
                "The bitcoin-cli utility provides a command line interface to interact with a " CLIENT_NAME " RPC server.\n"
                "\nIt can be used to query network information, manage wallets, create or broadcast transactions, and control the " CLIENT_NAME " server.\n"
                "\nUse the \"help\" command to list all commands. Use \"help <command>\" to show help for that command.\n"
                "The -named option allows you to specify parameters using the key=value format, eliminating the need to pass unused positional parameters.\n"
                "\n"
                "Usage: bitcoin-cli [options] <command> [params]\n"
                "or:    bitcoin-cli [options] -named <command> [name=value]...\n"
                "or:    bitcoin-cli [options] help\n"
                "or:    bitcoin-cli [options] help <command>\n"
                "\n";
            strUsage += "\n" + gArgs.GetHelpMessage();
        }

        tfm::format(std::cout, "%s", strUsage);
        if (argc < 2) {
            tfm::format(std::cerr, "Error: too few parameters\n");
            return EXIT_FAILURE;
        }
        return EXIT_SUCCESS;