| 8 | #include <string> |
| 9 | |
| 10 | int main(int argc, char **argv) { |
| 11 | std::string input_file_name, output_file_name; |
| 12 | int level{5}, subopt{0}; |
| 13 | |
| 14 | // app caption |
| 15 | CLI::App app{"CLI11 help"}; |
| 16 | |
| 17 | app.require_subcommand(1); |
| 18 | // subcommands options and flags |
| 19 | CLI::App *const encode = app.add_subcommand("e", "encode")->ignore_case(); // ignore case |
| 20 | encode->add_option("input", input_file_name, "input file") |
| 21 | ->option_text(" ") |
| 22 | ->required() |
| 23 | ->check(CLI::ExistingFile); // file must exist |
| 24 | encode->add_option("output", output_file_name, "output file")->option_text(" ")->required(); // required option |
| 25 | encode->add_option("-l, --level", level, "encoding level") |
| 26 | ->option_text("[1..9]") |
| 27 | ->check(CLI::Range(1, 9)) |
| 28 | ->default_val(5); // limit parameter range |
| 29 | encode->add_flag("-R, --remove", "remove input file"); // no parameter option |
| 30 | encode->add_flag("-s, --suboption", subopt, "suboption")->option_text(" "); |
| 31 | |
| 32 | CLI::App *const decode = app.add_subcommand("d", "decode")->ignore_case(); |
| 33 | decode->add_option("input", input_file_name, "input file")->option_text(" ")->required()->check(CLI::ExistingFile); |
| 34 | decode->add_option("output", output_file_name, "output file")->option_text(" ")->required(); |
| 35 | |
| 36 | // Usage message modification |
| 37 | std::string usage_msg = "Usage: " + std::string(argv[0]) + " <command> [options] <input-file> <output-file>"; |
| 38 | app.usage(usage_msg); |
| 39 | // flag to display full help at once |
| 40 | app.set_help_flag(""); |
| 41 | app.set_help_all_flag("-h, --help"); |
| 42 | |
| 43 | CLI11_PARSE(app, argc, argv); |
| 44 | |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | /* |
| 49 | $ ./help_usage -h |
nothing calls this directly
no test coverage detected