clap::simple_enum! [] [src]

macro_rules! simple_enum {
    ($e:ident => $($v:ident),+) => { ... };
}

Convenience macro generated a simple enum with variants to be used as a type when parsing arguments.

Example

simple_enum!{Foo => Bar, Baz, Qux}
// Foo enum can now be used via Foo::Bar, or Foo::Baz, etc
// and implements std::str::FromStr to use with the value_t! macros
fn main() {
    let m = App::new("app")
                .arg(Arg::from_usage("<foo> 'the foo'")
                    .possible_values(vec!["Bar", "Baz", "Qux"]))
                .get_matches();
    let f = value_t_or_exit!(m.value_of("foo"), Foo);

    // Use f like any other Foo variant...
}