#include "argument_parser.hpp" #include "conversion.hpp" #include "interfaces/randomization.hpp" #include #include #include namespace { void optarg_error(char arg, const std::string_view &error) { std::cout << "Error: Invalid option argument for -" << arg << ". " << error << std::endl; exit(EXIT_FAILURE); } /** * Returns the current optarg as a string view. */ std::string_view get_str_optarg() { return std::string_view(optarg); } /** * Returns the current optarg as a unsigned integer. * * @param arg The current command-line argument character * @param check_zero Whether or not to make sure that the result is not zero */ unsigned int get_uint_optarg(char arg, bool check_zero = false) { auto conversion_result = str_to_uint(get_str_optarg()); if (!conversion_result.success || (check_zero && conversion_result.result == 0)) { optarg_error(arg, conversion_result.fail_reason); } return conversion_result.result; } } // namespace ArgumentParser::ArgumentParser( IRandomNumberGeneratorFactory random_number_generator_factory) : _random_number_generator_factory(std::move(random_number_generator_factory)) { } ParsedArguments ArgumentParser::parse(const std::vector