#include #include #include #include "cmd_line_args.h" static struct option options[] = { {"help", no_argument, NULL, '?'}, {"version", no_argument, NULL, 'v'}, {"config-file", optional_argument, NULL, 'c'}, {NULL, 0, NULL, 0 } }; static constexpr auto optc = "?v:c:"; static constexpr auto help_format = "{0} v{1}\n\n" "Usage:\n" "Availabe options are:\n" "\t--help Show help\n" "\t--config-file Config file path\n" "\t--version Version of the {0}\n" "\n" "Usage example:\n" "{0} --config-file=scheduler.conf\n" "\n\n"; static constexpr auto version_format = "{0} v{1}\n\n" "Build with gcc-{2}"; void usage() { std::cout << fmt::format(help_format, APP_NAME, APP_VERSION) << std::endl; } void version() { std::cout << fmt::format(version_format, APP_NAME, APP_VERSION, APP_GCC) << std::endl; } parsed_opts parse_opts(int argc, char** argv) { if(argc < 1){ exit(1); } std::string config_file {""}; for(;;) { int opt_idx, c; if((c = getopt_long(argc, argv, optc, options, &opt_idx)) == -1) break; switch(c) { case '?': usage(); break; case 'v': version(); break; case 'c': config_file = optarg; break; default: exit(1); } } return {config_file}; }