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_bmp.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'utils/encrypt_bmp.cpp') diff --git a/utils/encrypt_bmp.cpp b/utils/encrypt_bmp.cpp index ad61266..7f1a890 100644 --- a/utils/encrypt_bmp.cpp +++ b/utils/encrypt_bmp.cpp @@ -29,7 +29,7 @@ namespace file::write_file(ciphertext_path, bmp.get_buffer(), bmp.get_size()); } - void encrypt_bmp(const Settings& settings) + void encrypt_bmp(const FileSettings& settings) { const auto& algorithm = settings.algorithm; const auto& mode = settings.mode; @@ -57,30 +57,30 @@ int main(int argc, char** argv) { try { - CommandLineParser cmd_parser{argv[0]}; + FileSettings settings{argv[0]}; + try { - const auto settings = cmd_parser.parse(argc, argv); - - if (cmd_parser.exit_with_usage()) - { - std::cout << cmd_parser; - return 0; - } - - encrypt_bmp(settings); + 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; } + + encrypt_bmp(settings); + } + catch (const aes::Error& e) + { + std::cerr << e; + return 1; } catch (const std::exception& e) { -- cgit v1.2.3