MCPcopy Create free account
hub / github.com/CLIUtils/CLI11 / main

Function main

examples/enum.cpp:16–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14enum class Level : int { High, Medium, Low };
15
16int main(int argc, char **argv) {
17 CLI::App app;
18
19 Level level{Level::Low};
20 // specify string->value mappings
21 std::map<std::string, Level> map{{"high", Level::High}, {"medium", Level::Medium}, {"low", Level::Low}};
22 // CheckedTransformer translates and checks whether the results are either in one of the strings or in one of the
23 // translations already
24 app.add_option("-l,--level", level, "Level settings")
25 ->required()
26 ->transform(CLI::CheckedTransformer(map, CLI::ignore_case));
27
28 CLI11_PARSE(app, argc, argv);
29
30 // CLI11's built in enum streaming can be used outside CLI11 like this:
31 using CLI::enums::operator<<;
32 std::cout << "Enum received: " << level << '\n';
33
34 return 0;
35}

Callers

nothing calls this directly

Calls 4

CheckedTransformerClass · 0.85
transformMethod · 0.80
requiredMethod · 0.45
add_optionMethod · 0.45

Tested by

no test coverage detected