clap/examples/arg_enum_case_sensitive.rs

28 lines
569 B
Rust
Raw Normal View History

2017-11-12 18:02:56 +00:00
#[macro_use]
extern crate clap;
#[macro_use]
extern crate clap_derive;
use clap::{App, Arg};
#[derive(ArgEnum, Debug)]
2017-11-15 17:49:55 +00:00
#[case_sensitive]
2017-11-12 18:02:56 +00:00
enum ArgChoice {
Foo,
Bar,
Baz,
}
fn main() {
let matches = App::new(env!("CARGO_PKG_NAME"))
.arg(Arg::with_name("arg")
.required(true)
.takes_value(true)
.possible_values(&ArgChoice::variants())
).get_matches();
let t = value_t!(matches.value_of("arg"), ArgChoice)
.unwrap_or_else(|e| e.exit());
println!("{:?}", t);
}