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