| 11 | #include <lyra/lyra.hpp> |
| 12 | |
| 13 | int main(int argc, const char** argv) |
| 14 | { |
| 15 | // Where we read in the argument value: |
| 16 | int width = 0; |
| 17 | |
| 18 | // The parser with the one option argument: |
| 19 | auto cli = lyra::cli() |
| 20 | | lyra::opt(width, "width") |
| 21 | ["-w"]["--width"]("How wide should it be?"); |
| 22 | |
| 23 | // ... |
| 24 | // end::part1[] |
| 25 | // tag::part2[] |
| 26 | // ... |
| 27 | |
| 28 | // Parse the program arguments: |
| 29 | auto result = cli.parse({ argc, argv }); |
| 30 | |
| 31 | // Check that the arguments where valid: |
| 32 | if (!result) |
| 33 | { |
| 34 | std::cerr << "Error in command line: " << result.message() << std::endl; |
| 35 | return 1; |
| 36 | } |
| 37 | |
| 38 | std::cout << "width = " << width << "\n"; |
| 39 | return 0; |
| 40 | } |
| 41 | // end::part2[] |