From f36132a8370096adc953a7fcec69f55070eb2e71 Mon Sep 17 00:00:00 2001 From: stoffu Date: Sun, 15 Apr 2018 14:52:53 +0900 Subject: [PATCH] wallet cli/rpc: terminate execution with code 0 when --help or --version is given --- src/gen_multisig/gen_multisig.cpp | 6 +++++- src/simplewallet/simplewallet.cpp | 9 ++++++++- src/wallet/wallet_args.cpp | 16 +++++++++++----- src/wallet/wallet_args.h | 7 +++++-- src/wallet/wallet_rpc_server.cpp | 8 +++++++- 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/gen_multisig/gen_multisig.cpp b/src/gen_multisig/gen_multisig.cpp index 943589b4a..03e0a7946 100644 --- a/src/gen_multisig/gen_multisig.cpp +++ b/src/gen_multisig/gen_multisig.cpp @@ -174,7 +174,9 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_stagenet); command_line::add_arg(desc_params, arg_create_address_file); - const auto vm = wallet_args::main( + boost::optional vm; + bool should_terminate = false; + std::tie(vm, should_terminate) = wallet_args::main( argc, argv, "monero-gen-multisig [(--testnet|--stagenet)] [--filename-base=] [--scheme=M/N] [--threshold=M] [--participants=N]", genms::tr("This program generates a set of multisig wallets - use this simpler scheme only if all the participants trust each other"), @@ -185,6 +187,8 @@ int main(int argc, char* argv[]) ); if (!vm) return 1; + if (should_terminate) + return 0; bool testnet, stagenet; uint32_t threshold = 0, total = 0; diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 639b394f3..ca10d3f3a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -7505,7 +7505,9 @@ int main(int argc, char* argv[]) po::positional_options_description positional_options; positional_options.add(arg_command.name, -1); - const auto vm = wallet_args::main( + boost::optional vm; + bool should_terminate = false; + std::tie(vm, should_terminate) = wallet_args::main( argc, argv, "monero-wallet-cli [--wallet-file=|--generate-new-wallet=] []", sw::tr("This is the command line monero wallet. It needs to connect to a monero\ndaemon to work correctly.\nWARNING: Do not reuse your Monero keys on an another fork, UNLESS this fork has key reuse mitigations built in. Doing so will harm your privacy."), @@ -7520,6 +7522,11 @@ int main(int argc, char* argv[]) return 1; } + if (should_terminate) + { + return 0; + } + cryptonote::simple_wallet w; const bool r = w.init(*vm); CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet")); diff --git a/src/wallet/wallet_args.cpp b/src/wallet/wallet_args.cpp index a6ff63dd3..6311e7700 100644 --- a/src/wallet/wallet_args.cpp +++ b/src/wallet/wallet_args.cpp @@ -82,7 +82,7 @@ namespace wallet_args return i18n_translate(str, "wallet_args"); } - boost::optional main( + std::pair, bool> main( int argc, char** argv, const char* const usage, const char* const notice, @@ -127,6 +127,7 @@ namespace wallet_args po::options_description desc_all; desc_all.add(desc_general).add(desc_params); po::variables_map vm; + bool should_terminate = false; bool r = command_line::handle_error_helper(desc_all, [&]() { auto parser = po::command_line_parser(argc, argv).options(desc_all).positional(positional_options); @@ -139,12 +140,14 @@ namespace wallet_args "daemon to work correctly.") << ENDL; Print(print) << wallet_args::tr("Usage:") << ENDL << " " << usage; Print(print) << desc_all; - return false; + should_terminate = true; + return true; } else if (command_line::get_arg(vm, command_line::arg_version)) { Print(print) << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")"; - return false; + should_terminate = true; + return true; } if(command_line::has_arg(vm, arg_config_file)) @@ -167,7 +170,10 @@ namespace wallet_args return true; }); if (!r) - return boost::none; + return {boost::none, true}; + + if (should_terminate) + return {std::move(vm), should_terminate}; std::string log_path; if (!command_line::is_arg_defaulted(vm, arg_log_file)) @@ -196,6 +202,6 @@ namespace wallet_args Print(print) << boost::format(wallet_args::tr("Logging to %s")) % log_path; - return {std::move(vm)}; + return {std::move(vm), should_terminate}; } } diff --git a/src/wallet/wallet_args.h b/src/wallet/wallet_args.h index af6685845..a1f251144 100644 --- a/src/wallet/wallet_args.h +++ b/src/wallet/wallet_args.h @@ -44,8 +44,11 @@ namespace wallet_args concurrency. Log file and concurrency arguments are handled, along with basic global init for the wallet process. - \return The list of parsed options, iff there are no errors.*/ - boost::optional main( + \return + pair.first: The list of parsed options, iff there are no errors. + pair.second: Should the execution terminate succesfully without actually launching the application + */ + std::pair, bool> main( int argc, char** argv, const char* const usage, const char* const notice, diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index a9d211532..8dcdfd1b3 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -2895,7 +2895,9 @@ int main(int argc, char** argv) { command_line::add_arg(desc_params, arg_wallet_dir); command_line::add_arg(desc_params, arg_prompt_for_password); - const auto vm = wallet_args::main( + boost::optional vm; + bool should_terminate = false; + std::tie(vm, should_terminate) = wallet_args::main( argc, argv, "monero-wallet-rpc [--wallet-file=|--generate-from-json=|--wallet-dir=] [--rpc-bind-port=]", tools::wallet_rpc_server::tr("This is the RPC monero wallet. It needs to connect to a monero\ndaemon to work correctly."), @@ -2909,6 +2911,10 @@ int main(int argc, char** argv) { { return 1; } + if (should_terminate) + { + return 0; + } std::unique_ptr wal; try