[Update]
Okay, it turns out that the enum example has been updated to use CheckedTransformer. Fix the sample below and keep this repo as a reference. Ref: #239 and #263.
CLI11 added map support to IsMember since #228.
However, I cannot have the example running.
Here is a sample:
std::map<std::string, Level> map = {{"High", Level::High},
{"Medium", Level::Medium},
{"Low", Level::Low}};
app.add_flag("-f,--foo", foo, "Set foo");
app.add_flag("-b,--bar", bar, "Set bar");
app.add_option("-l,--level", level, "Level settings")
->transform(CLI::CheckedTransformer(map, CLI::ignore_case));
// Deprecated:
// ->transform(CLI::IsMember(map, CLI::ignore_case)
// | CLI::IsMember({Level::High, Level::Medium, Level::Low}));
And the output:
$ ./cli --foo -l 0 # Works correctly
level: 0
foo: YES
bar: NO
$ ./cli --foo -l Low # Works correctly as well
level: 0
foo: YES
bar: NO
# No more exceptions.
# $ ./cli --foo -l Low # Exception
# --level: Low
# Run with --help for more information.
Note the exception raised when using text "Low".
This sample is built with:
$ clang++ -std=c++11 -I boost -I cli11/include main.cc -o cli
$ clang++ --version
Apple clang version 11.0.0 (clang-1100.0.33.12)
Target: x86_64-apple-darwin18.7.0