From 06b2428c2afaa36997a9d341bd497d42aa0fef89 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 20 Jun 2017 18:22:00 +0300 Subject: utils: refactor command-line arguments parsing + update usage messages. --- utils/encrypt_block.cpp | 65 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 33 deletions(-) (limited to 'utils/encrypt_block.cpp') diff --git a/utils/encrypt_block.cpp b/utils/encrypt_block.cpp index 5c02d92..b8cb55e 100644 --- a/utils/encrypt_block.cpp +++ b/utils/encrypt_block.cpp @@ -164,49 +164,48 @@ int main(int argc, char** argv) { try { - CommandLineParser cmd_parser{argv[0]}; + BlockSettings settings{argv[0]}; + try { - std::vector inputs; - const auto settings = cmd_parser.parse(argc, argv, inputs); - - if (cmd_parser.exit_with_usage()) - { - std::cout << cmd_parser; - return 0; - } - - for (const auto& input : inputs) - { - if (settings.use_boxes) - { - encrypt_using_boxes( - settings.algorithm, - settings.mode, - input); - } - else - { - encrypt_using_cxx_api( - settings.algorithm, - settings.mode, - input, - settings.verbose); - } - } + settings.parse(argc, argv); } catch (const boost::program_options::error& e) { - std::cerr << "Usage error: " << e.what() << "\n"; - std::cerr << cmd_parser; + settings.usage_error(e); return 1; } - catch (const aes::Error& e) + + if (settings.exit_with_usage) { - std::cerr << e; - return 1; + settings.usage(); + return 0; + } + + for (const auto& input : settings.inputs) + { + if (settings.use_boxes) + { + encrypt_using_boxes( + settings.algorithm, + settings.mode, + input); + } + else + { + encrypt_using_cxx_api( + settings.algorithm, + settings.mode, + input, + settings.verbose); + } } } + catch (const aes::Error& e) + { + std::cerr << e; + return 1; + } catch (const std::exception& e) { std::cerr << e.what() << "\n"; -- cgit v1.2.3