Commit 3da480792b18f0debd181270372cb2d560494a52
1 parent
00e0506f
Adding enum example
Showing
2 changed files
with
24 additions
and
0 deletions
examples/CMakeLists.txt
| @@ -19,3 +19,4 @@ add_cli_exe(subcommands subcommands.cpp) | @@ -19,3 +19,4 @@ add_cli_exe(subcommands subcommands.cpp) | ||
| 19 | add_cli_exe(groups groups.cpp) | 19 | add_cli_exe(groups groups.cpp) |
| 20 | add_cli_exe(inter_argument_order inter_argument_order.cpp) | 20 | add_cli_exe(inter_argument_order inter_argument_order.cpp) |
| 21 | add_cli_exe(prefix_command prefix_command.cpp) | 21 | add_cli_exe(prefix_command prefix_command.cpp) |
| 22 | +add_cli_exe(enum enum.cpp) |
examples/enum.cpp
0 → 100644
| 1 | +#include <CLI/CLI.hpp> | ||
| 2 | + | ||
| 3 | +enum Level : std::int32_t { | ||
| 4 | + High, | ||
| 5 | + Medium, | ||
| 6 | + Low | ||
| 7 | +}; | ||
| 8 | + | ||
| 9 | +int main(int argc, char** argv) { | ||
| 10 | + CLI::App app; | ||
| 11 | + | ||
| 12 | + Level level; | ||
| 13 | + app.add_set("-l,--level", level, {High, Medium, Low}, "Level settings") | ||
| 14 | + ->set_type_name("enum/Level in {High=0, Medium=1, Low=2}"); | ||
| 15 | + | ||
| 16 | + try { | ||
| 17 | + app.parse(argc, argv); | ||
| 18 | + } catch (CLI::Error const& e) { | ||
| 19 | + app.exit(e); | ||
| 20 | + } | ||
| 21 | + return 0; | ||
| 22 | +} | ||
| 23 | + |