diff --git a/README.md b/README.md index c4a8550d..fbf37a6a 100644 --- a/README.md +++ b/README.md @@ -825,6 +825,7 @@ Several short examples of different features are included in the repository. A b - [callback_passthrough](https://github.com/CLIUtils/CLI11/blob/master/examples/callback_passthrough.cpp): Example of directly passing remaining arguments through to a callback function which generates a CLI11 application based on existing arguments. - [digit_args](https://github.com/CLIUtils/CLI11/blob/master/examples/digit_args.cpp): Based on [Issue #123](https://github.com/CLIUtils/CLI11/issues/123), uses digit flags to pass a value - [enum](https://github.com/CLIUtils/CLI11/blob/master/examples/enum.cpp): Using enumerations in an option, and the use of [CheckedTransformer](#transforming-validators) + - [enum_ostream](https://github.com/CLIUtils/CLI11/blob/master/examples/enum_ostream.cpp): In addition to the contents of example enum.cpp, this example shows how a custom ostream operator overrides CLI11's enum streaming. - [formatter](https://github.com/CLIUtils/CLI11/blob/master/examples/formatter.cpp): Illustrating usage of a custom formatter - [groups](https://github.com/CLIUtils/CLI11/blob/master/examples/groups.cpp): Example using groups of options for help grouping and a the timer helper class - [inter_argument_order](https://github.com/CLIUtils/CLI11/blob/master/examples/inter_argument_order.cpp): An app to practice mixing unlimited arguments, but still recover the original order. @@ -846,7 +847,7 @@ Several short examples of different features are included in the repository. A b ## Contribute -To contribute, open an [issue][github issues] or [pull request][github pull requests] on GitHub, or ask a question on [gitter][]. The is also a short note to contributors [here](./.github/CONTRIBUTING.md). +To contribute, open an [issue][github issues] or [pull request][github pull requests] on GitHub, or ask a question on [gitter][]. There is also a short note to contributors [here](./.github/CONTRIBUTING.md). This readme roughly follows the [Standard Readme Style][] and includes a mention of almost every feature of the library. More complex features are documented in more detail in the [CLI11 tutorial GitBook][gitbook]. This project was created by [Henry Schreiner](https://github.com/henryiii). diff --git a/examples/enum.cpp b/examples/enum.cpp index 6e0d69b2..c9616241 100644 --- a/examples/enum.cpp +++ b/examples/enum.cpp @@ -1,15 +1,15 @@ #include +#include enum class Level : int { High, Medium, Low }; int main(int argc, char **argv) { CLI::App app; - Level level; + Level level{Level::Low}; // specify string->value mappings - std::vector> 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 + std::map map{{"high", Level::High}, {"medium", Level::Medium}, {"low", Level::Low}}; + // CheckedTransformer translates and checks whether the results are either in one of the strings or in one of the // translations already app.add_option("-l,--level", level, "Level settings") ->required() diff --git a/examples/enum_ostream.cpp b/examples/enum_ostream.cpp index 7e4be99f..cf8b3295 100644 --- a/examples/enum_ostream.cpp +++ b/examples/enum_ostream.cpp @@ -2,30 +2,30 @@ enum class Level : int { High, Medium, Low }; -// this breaks the code -inline std::ostream &operator<<(std::ostream &o, const Level &l) { - switch(l) { +// Defining operator<<() for your enum class (in this case for 'Level') overrides CLI11's enum streaming +inline std::ostream &operator<<(std::ostream &os, const Level &level) { + switch(level) { case Level::High: - o << "High"; + os << "High"; break; case Level::Medium: - o << "Medium"; + os << "Medium"; break; case Level::Low: - o << "Low"; + os << "Low"; break; } - return o; + os << " (ft rom custom ostream)"; + return os; } int main(int argc, char **argv) { CLI::App app; - Level level; + Level level{Level::Low}; // specify string->value mappings - std::vector> 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 + std::map map{{"high", Level::High}, {"medium", Level::Medium}, {"low", Level::Low}}; + // CheckedTransformer translates and checks whether the results are either in one of the strings or in one of the // translations already app.add_option("-l,--level", level, "Level settings") ->required()