| 11 | #include <lyra/lyra.hpp> |
| 12 | |
| 13 | int main(int argc, const char** argv) |
| 14 | { |
| 15 | // Where we read in the argument values: |
| 16 | int width = 0; |
| 17 | std::string name; |
| 18 | bool doIt = false; |
| 19 | |
| 20 | // The parser with the multiple option arguments. They are composed |
| 21 | // together by the "|" operator. |
| 22 | auto cli = lyra::cli(); |
| 23 | cli.add_argument(lyra::opt(width, "width") |
| 24 | .name("-w").name("--width").help("How wide should it be?")); |
| 25 | cli.add_argument(lyra::opt(name, "name") |
| 26 | .name("-n").name("--name").help("By what name should I be known")); |
| 27 | cli.add_argument(lyra::opt(doIt) |
| 28 | .name("-d").name("--doit").help("Do the thing")); |
| 29 | |
| 30 | // Parse the program arguments: |
| 31 | auto result = cli.parse({ argc, argv }); |
| 32 | |
| 33 | // Check that the arguments where valid: |
| 34 | if (!result) |
| 35 | { |
| 36 | std::cerr << "Error in command line: " << result.message() << std::endl; |
| 37 | return 1; |
| 38 | } |
| 39 | |
| 40 | std::cout << "width = " << width << ", name = " << name << ", doIt = " << doIt << "\n"; |
| 41 | return 0; |
| 42 | } |
| 43 | // end::doc[] |