Skip to content

Commit

Permalink
End execution with code 0 when help or version is given
Browse files Browse the repository at this point in the history
  • Loading branch information
miltonf committed Feb 24, 2019
1 parent 653f2ad commit affe2d0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 11 deletions.
8 changes: 6 additions & 2 deletions src/gen_multisig/gen_multisig.cpp
Expand Up @@ -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_stagenet);
command_line::add_arg(desc_params, arg_create_address_file); command_line::add_arg(desc_params, arg_create_address_file);


const auto vm = wallet_args::main( boost::optional<po::variables_map> vm;
bool should_terminate = false;
std::tie(vm, should_terminate) = wallet_args::main(
argc, argv, argc, argv,
"monerov-gen-multisig [(--testnet|--stagenet)] [--filename-base=<filename>] [--scheme=M/N] [--threshold=M] [--participants=N]", "monerov-gen-multisig [(--testnet|--stagenet)] [--filename-base=<filename>] [--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"), genms::tr("This program generates a set of multisig wallets - use this simpler scheme only if all the participants trust each other"),
Expand All @@ -185,7 +187,9 @@ int main(int argc, char* argv[])
); );
if (!vm) if (!vm)
return 1; return 1;

if (should_terminate)
return 0;

bool testnet, stagenet; bool testnet, stagenet;
uint32_t threshold = 0, total = 0; uint32_t threshold = 0, total = 0;
std::string basename; std::string basename;
Expand Down
9 changes: 8 additions & 1 deletion src/simplewallet/simplewallet.cpp
Expand Up @@ -7558,7 +7558,9 @@ int main(int argc, char* argv[])
po::positional_options_description positional_options; po::positional_options_description positional_options;
positional_options.add(arg_command.name, -1); positional_options.add(arg_command.name, -1);


const auto vm = wallet_args::main( boost::optional<po::variables_map> vm;
bool should_terminate = false;
std::tie(vm, should_terminate) = wallet_args::main(
argc, argv, argc, argv,
"monerov-wallet-cli [--wallet-file=<file>|--generate-new-wallet=<file>] [<COMMAND>]", "monerov-wallet-cli [--wallet-file=<file>|--generate-new-wallet=<file>] [<COMMAND>]",
sw::tr("This is the command line MoneroV wallet. It needs to connect to a monerov\ndaemon to work correctly.\nWARNING: Do not reuse your MoneroV keys on an another fork unless this fork has key reuse mitigations built in. Doing so will harm your privacy."), sw::tr("This is the command line MoneroV wallet. It needs to connect to a monerov\ndaemon to work correctly.\nWARNING: Do not reuse your MoneroV keys on an another fork unless this fork has key reuse mitigations built in. Doing so will harm your privacy."),
Expand All @@ -7573,6 +7575,11 @@ int main(int argc, char* argv[])
return 1; return 1;
} }


if (should_terminate)
{
return 0;
}

cryptonote::simple_wallet w; cryptonote::simple_wallet w;
const bool r = w.init(*vm); const bool r = w.init(*vm);
CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet")); CHECK_AND_ASSERT_MES(r, 1, sw::tr("Failed to initialize wallet"));
Expand Down
16 changes: 11 additions & 5 deletions src/wallet/wallet_args.cpp
Expand Up @@ -82,7 +82,7 @@ namespace wallet_args
return i18n_translate(str, "wallet_args"); return i18n_translate(str, "wallet_args");
} }


boost::optional<boost::program_options::variables_map> main( std::pair<boost::optional<boost::program_options::variables_map>, bool> main(
int argc, char** argv, int argc, char** argv,
const char* const usage, const char* const usage,
const char* const notice, const char* const notice,
Expand Down Expand Up @@ -127,6 +127,7 @@ namespace wallet_args
po::options_description desc_all; po::options_description desc_all;
desc_all.add(desc_general).add(desc_params); desc_all.add(desc_general).add(desc_params);
po::variables_map vm; po::variables_map vm;
bool should_terminate = false;
bool r = command_line::handle_error_helper(desc_all, [&]() bool r = command_line::handle_error_helper(desc_all, [&]()
{ {
auto parser = po::command_line_parser(argc, argv).options(desc_all).positional(positional_options); auto parser = po::command_line_parser(argc, argv).options(desc_all).positional(positional_options);
Expand All @@ -139,12 +140,14 @@ namespace wallet_args
"daemon to work correctly.") << ENDL; "daemon to work correctly.") << ENDL;
Print(print) << wallet_args::tr("Usage:") << ENDL << " " << usage; Print(print) << wallet_args::tr("Usage:") << ENDL << " " << usage;
Print(print) << desc_all; Print(print) << desc_all;
return false; should_terminate = true;
return true;
} }
else if (command_line::get_arg(vm, command_line::arg_version)) else if (command_line::get_arg(vm, command_line::arg_version))
{ {
Print(print) << "MoneroV '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")"; Print(print) << "MoneroV '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")";
return false; should_terminate = true;
return true;
} }


if(command_line::has_arg(vm, arg_config_file)) if(command_line::has_arg(vm, arg_config_file))
Expand All @@ -167,7 +170,10 @@ namespace wallet_args
return true; return true;
}); });
if (!r) if (!r)
return boost::none; return {boost::none, true};

if (should_terminate)
return {std::move(vm), should_terminate};


std::string log_path; std::string log_path;
if (!command_line::is_arg_defaulted(vm, arg_log_file)) if (!command_line::is_arg_defaulted(vm, arg_log_file))
Expand Down Expand Up @@ -200,6 +206,6 @@ namespace wallet_args


Print(print) << boost::format(wallet_args::tr("Logging to %s")) % log_path; Print(print) << boost::format(wallet_args::tr("Logging to %s")) % log_path;


return {std::move(vm)}; return {std::move(vm), should_terminate};
} }
} }
7 changes: 5 additions & 2 deletions src/wallet/wallet_args.h
Expand Up @@ -44,8 +44,11 @@ namespace wallet_args
concurrency. Log file and concurrency arguments are handled, along with basic concurrency. Log file and concurrency arguments are handled, along with basic
global init for the wallet process. global init for the wallet process.
\return The list of parsed options, iff there are no errors.*/ \return
boost::optional<boost::program_options::variables_map> main( 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<boost::optional<boost::program_options::variables_map>, bool> main(
int argc, char** argv, int argc, char** argv,
const char* const usage, const char* const usage,
const char* const notice, const char* const notice,
Expand Down
9 changes: 8 additions & 1 deletion src/wallet/wallet_rpc_server.cpp
Expand Up @@ -2907,7 +2907,9 @@ int main(int argc, char** argv) {
command_line::add_arg(desc_params, arg_wallet_dir); command_line::add_arg(desc_params, arg_wallet_dir);
command_line::add_arg(desc_params, arg_prompt_for_password); command_line::add_arg(desc_params, arg_prompt_for_password);


const auto vm = wallet_args::main( boost::optional<po::variables_map> vm;
bool should_terminate = false;
std::tie(vm, should_terminate) = wallet_args::main(
argc, argv, argc, argv,
"monerov-wallet-rpc [--wallet-file=<file>|--generate-from-json=<file>|--wallet-dir=<directory>] [--rpc-bind-port=<port>]", "monerov-wallet-rpc [--wallet-file=<file>|--generate-from-json=<file>|--wallet-dir=<directory>] [--rpc-bind-port=<port>]",
tools::wallet_rpc_server::tr("This is the RPC MoneroV wallet. It needs to connect to a monerov\ndaemon to work correctly."), tools::wallet_rpc_server::tr("This is the RPC MoneroV wallet. It needs to connect to a monerov\ndaemon to work correctly."),
Expand All @@ -2922,6 +2924,11 @@ int main(int argc, char** argv) {
return 1; return 1;
} }


if (should_terminate)
{
return 0;
}

std::unique_ptr<tools::wallet2> wal; std::unique_ptr<tools::wallet2> wal;
try try
{ {
Expand Down

0 comments on commit affe2d0

Please sign in to comment.