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.
| 202 | // CONTINUE_EXECUTION when it's expected to continue further. |
| 203 | // |
| 204 | static int AppInitRPC(int argc, char* argv[]) |
| 205 | { |
| 206 | SetupCliArgs(gArgs); |
| 207 | std::string error; |
| 208 | if (!gArgs.ParseParameters(argc, argv, error)) { |
| 209 | tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error); |
| 210 | return EXIT_FAILURE; |
| 211 | } |
| 212 | if (argc < 2 || HelpRequested(gArgs) || gArgs.GetBoolArg("-version", false)) { |
| 213 | std::string strUsage = CLIENT_NAME " RPC client version " + FormatFullVersion() + "\n"; |
| 214 | |
| 215 | if (gArgs.GetBoolArg("-version", false)) { |
| 216 | strUsage += FormatParagraph(LicenseInfo()); |
| 217 | } else { |
| 218 | strUsage += "\n" |
| 219 | "The bitcoin-cli utility provides a command line interface to interact with a " CLIENT_NAME " RPC server.\n" |
| 220 | "\nIt can be used to query network information, manage wallets, create or broadcast transactions, and control the " CLIENT_NAME " server.\n" |
| 221 | "\nUse the \"help\" command to list all commands. Use \"help <command>\" to show help for that command.\n" |
| 222 | "The -named option allows you to specify parameters using the key=value format, eliminating the need to pass unused positional parameters.\n" |
| 223 | "\n" |
| 224 | "Usage: bitcoin-cli [options] <command> [params]\n" |
| 225 | "or: bitcoin-cli [options] -named <command> [name=value]...\n" |
| 226 | "or: bitcoin-cli [options] help\n" |
| 227 | "or: bitcoin-cli [options] help <command>\n" |
| 228 | "\n"; |
| 229 | strUsage += "\n" + gArgs.GetHelpMessage(); |
| 230 | } |
| 231 | |
| 232 | tfm::format(std::cout, "%s", strUsage); |
| 233 | if (argc < 2) { |
| 234 | tfm::format(std::cerr, "Error: too few parameters\n"); |
| 235 | return EXIT_FAILURE; |
| 236 | } |
| 237 | return EXIT_SUCCESS; |
| 238 | } |
| 239 | if (!CheckDataDirOption(gArgs)) { |
| 240 | tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "")); |
| 241 | return EXIT_FAILURE; |
| 242 | } |
| 243 | if (!gArgs.ReadConfigFiles(error, true)) { |
| 244 | tfm::format(std::cerr, "Error reading configuration file: %s\n", error); |
| 245 | return EXIT_FAILURE; |
| 246 | } |
| 247 | // Check for chain settings (BaseParams() calls are only valid after this clause) |
| 248 | try { |
| 249 | SelectBaseParams(gArgs.GetChainType()); |
| 250 | } catch (const std::exception& e) { |
| 251 | tfm::format(std::cerr, "Error: %s\n", e.what()); |
| 252 | return EXIT_FAILURE; |
| 253 | } |
| 254 | return CONTINUE_EXECUTION; |
| 255 | } |
| 256 | |
| 257 | struct HTTPResponse |
| 258 | { |
no test coverage detected