Git Product home page Git Product logo

cli11-ismember's Introduction

CLI11 IsMember Test

[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

cli11-ismember's People

Contributors

hanstzou avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.