| 37 | #include <vector> |
| 38 | |
| 39 | int main(int argc, const char ** argv) |
| 40 | { |
| 41 | // Default to showing a full screen 4/3 aspect |
| 42 | bool show_full_screen = true; |
| 43 | float aspect = 4.0f / 3.0f; |
| 44 | |
| 45 | // If it's not full screen the size will be specified. |
| 46 | unsigned width = 0; |
| 47 | unsigned height = 0; |
| 48 | |
| 49 | // Did the user ask for help? |
| 50 | bool get_help = false; |
| 51 | |
| 52 | lyra::cli cli; |
| 53 | cli.add_argument(lyra::help(get_help)) |
| 54 | .add_argument(lyra::opt(aspect, "aspect") // <1> |
| 55 | .name("--aspect") |
| 56 | .help("Full-screen aspect ratio window.")) |
| 57 | .add_argument(lyra::group([&](const lyra::group &) { |
| 58 | show_full_screen = false; |
| 59 | }) // <2> |
| 60 | .add_argument(lyra::opt(width, "width") // <3> |
| 61 | .required() |
| 62 | .name("--width") |
| 63 | .help("Width of window.")) |
| 64 | .add_argument(lyra::opt(height, "height") |
| 65 | .required() // <4> |
| 66 | .name("--height") |
| 67 | .help("Height of window."))); |
| 68 | |
| 69 | // Parse the program arguments. |
| 70 | auto result = cli.parse({ argc, argv }); |
| 71 | |
| 72 | if (get_help) |
| 73 | { |
| 74 | std::cout << cli; |
| 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | // Check that the arguments where valid. |
| 79 | if (!result) |
| 80 | { |
| 81 | std::cerr << "Error in command line: " << result.message() |
| 82 | << std::endl; |
| 83 | return 1; |
| 84 | } |
| 85 | |
| 86 | if (show_full_screen) |
| 87 | { |
| 88 | std::cout << "Full screen aspect = " << aspect << "\n"; |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | std::cout << "Window size = " << width << " x " << height << "\n"; |
| 93 | } |
| 94 | |
| 95 | return 0; |
| 96 | } |