From 6bc9eb38f74f53f42d2e4fe1e8b7071aed9de921 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Mon, 21 Feb 2022 11:15:11 +0300 Subject: [PATCH] #282 Fix termination when the required argument for option is missing --- programs/cli_wallet/main.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index a0449ce0..e2f5a182 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -86,16 +86,24 @@ int main(int argc, char **argv) { bpo::variables_map options; - bpo::parsed_options po = bpo::command_line_parser(argc, argv).options(opts).allow_unregistered().run(); - std::vector unrecognized = bpo::collect_unrecognized(po.options, bpo::include_positional); - if (unrecognized.size() > 0) { - std::cout << "Unknown parameter(s): " << std::endl; - for (auto s : unrecognized) { - std::cout << " " << s << std::endl; + try + { + bpo::parsed_options po = bpo::command_line_parser(argc, argv).options(opts).allow_unregistered().run(); + std::vector unrecognized = bpo::collect_unrecognized(po.options, bpo::include_positional); + if (unrecognized.size() > 0) { + std::cout << "Unknown parameter(s): " << std::endl; + for (auto s : unrecognized) { + std::cout << " " << s << std::endl; + } + return 0; } + bpo::store(po, options); + } + catch (const boost::program_options::invalid_command_line_syntax & e) + { + std::cout << e.what() << std::endl; return 0; } - bpo::store(po, options); if (options.count("help")) { std::cout << opts << "\n"; -- 2.45.2