| 2 | #include <iostream> |
| 3 | |
| 4 | int main(int argc, char **argv) { |
| 5 | using std::cout; |
| 6 | using std::endl; |
| 7 | CLI::App app{"Flag example program"}; |
| 8 | |
| 9 | /// [define] |
| 10 | bool flag_bool; |
| 11 | app.add_flag("--bool,-b", flag_bool, "This is a bool flag"); |
| 12 | |
| 13 | int flag_int; |
| 14 | app.add_flag("-i,--int", flag_int, "This is an int flag"); |
| 15 | |
| 16 | CLI::Option *flag_plain = app.add_flag("--plain,-p", "This is a plain flag"); |
| 17 | /// [define] |
| 18 | |
| 19 | /// [parser] |
| 20 | try { |
| 21 | app.parse(argc, argv); |
| 22 | } catch(const CLI::ParseError &e) { |
| 23 | return app.exit(e); |
| 24 | } |
| 25 | /// [parser] |
| 26 | |
| 27 | /// [usage] |
| 28 | cout << "The flags program" << endl; |
| 29 | if(flag_bool) |
| 30 | cout << "Bool flag passed" << endl; |
| 31 | if(flag_int > 0) |
| 32 | cout << "Flag int: " << flag_int << endl; |
| 33 | if(*flag_plain) |
| 34 | cout << "Flag plain: " << flag_plain->count() << endl; |
| 35 | /// [usage] |
| 36 | } |