enum_in_args/
enum_in_args.rs1use std::str::FromStr;
4
5use bpaf::*;
6
7#[derive(Debug, Clone)]
8enum Baz {
9 Foo,
10 Bar,
11 FooBar,
12}
13
14impl FromStr for Baz {
15 type Err = String;
16 fn from_str(s: &str) -> Result<Self, String>
17 where
18 Self: Sized,
19 {
20 match s {
21 "foo" => Ok(Baz::Foo),
22 "bar" => Ok(Baz::Bar),
23 "foobar" => Ok(Baz::FooBar),
24 _ => Err("Expected foo|bar|foobar".to_string()),
25 }
26 }
27}
28fn main() {
29 let opt = long("baz")
30 .short('b')
31 .help("choose between foo, bar or foobar")
32 .argument::<Baz>("CMD")
33 .to_options()
34 .run();
35
36 println!("{:#?}", opt);
37}