| 10 | #include <lyra/lyra.hpp> |
| 11 | |
| 12 | int main(int argc, const char** argv) |
| 13 | { |
| 14 | std::string choice; |
| 15 | // Ex: <exe> --choice=red |
| 16 | auto cli = lyra::cli() |
| 17 | | lyra::opt(choice, "-c")["--choice"] |
| 18 | .choices("red", "green", "blue"); |
| 19 | auto result = cli.parse({ argc, argv }); |
| 20 | if (result) |
| 21 | { |
| 22 | std::cout << "Your preferred color is " << choice << "\n"; |
| 23 | return 0; |
| 24 | } |
| 25 | else |
| 26 | { |
| 27 | std::cerr << result.message() << "\n"; |
| 28 | return 1; |
| 29 | } |
| 30 | } |
| 31 | // end::part1[] |