1
0
mirror of https://github.com/CLIUtils/CLI11.git synced 2025-04-29 12:13:52 +00:00
CLI11/examples/enum.cpp
Philip Top e9934e058d add transformer and checkedTransformer (#239)
* add transform and checkedTransform tests

add Transformer and CheckedTransformer validators

* Eliminate the Validator description string, some code cleanup

add tests

Make Validators a full Object and remove friend,  move to descriptions instead of overriding type name.

update validators to actually merge the type strings and use all validators in the type outputs

rework join so it works without the start variable,  allow some forwarding references in the validator types, some tests for non-copyable maps, and transforms

merge the search function and enable use of member search function,  make the pair adapters forwarding instead of copying

* add a few more tests and documentation

fix some gcc 4.7 issues and add a few more test cases and more parts of the README

Work on ReadMe and add Bound validator to clamp values

* updates to README.md

* Add some more in TOC of README and fix style in Option.hpp
2019-03-02 12:24:26 +01:00

26 lines
822 B
C++

#include <CLI/CLI.hpp>
enum class Level : int { High, Medium, Low };
int main(int argc, char **argv) {
CLI::App app;
Level level;
// specify string->value mappings
std::vector<std::pair<std::string, Level>> map{
{"high", Level::High}, {"medium", Level::Medium}, {"low", Level::Low}};
// checked Transform does the translation and checks the results are either in one of the strings or one of the
// translations already
app.add_option("-l,--level", level, "Level settings")
->required()
->transform(CLI::CheckedTransformer(map, CLI::ignore_case));
CLI11_PARSE(app, argc, argv);
// CLI11's built in enum streaming can be used outside CLI11 like this:
using namespace CLI::enums;
std::cout << "Enum received: " << level << std::endl;
return 0;
}