enum_tuple/
enum_tuple.rs

1//! How to extract subcommands' args into external structs.
2
3use bpaf::*;
4
5#[derive(Debug, Clone)]
6pub struct Foo {
7    pub bar: Option<String>,
8}
9
10#[derive(Debug, Clone)]
11pub enum Command {
12    Foo(Foo),
13}
14
15fn main() {
16    let bar = short('b')
17        .long("bar")
18        .help("some bar command")
19        .argument::<String>("BAR")
20        .optional();
21
22    let bar_cmd = construct!(Foo { bar })
23        .to_options()
24        .descr("This command will try to do foo given a bar argument");
25
26    let opt = bar_cmd
27        .command("foo")
28        .help("command for doing foo")
29        .map(Command::Foo)
30        .to_options()
31        .run();
32
33    println!("{:#?}", opt);
34}