2020-02-13 15:21:01 +00:00
|
|
|
use clap::Clap;
|
|
|
|
|
2020-07-07 11:17:36 +00:00
|
|
|
#[derive(Clap, PartialEq, Debug)]
|
|
|
|
struct Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
sub: Box<Sub>,
|
|
|
|
}
|
2020-02-13 15:21:01 +00:00
|
|
|
|
2020-07-07 11:17:36 +00:00
|
|
|
#[derive(Clap, PartialEq, Debug)]
|
|
|
|
enum Sub {
|
|
|
|
Flame {
|
|
|
|
#[clap(flatten)]
|
|
|
|
arg: Box<Ext>,
|
|
|
|
},
|
|
|
|
}
|
2020-02-13 15:21:01 +00:00
|
|
|
|
2020-07-07 11:17:36 +00:00
|
|
|
#[derive(Clap, PartialEq, Debug)]
|
|
|
|
struct Ext {
|
|
|
|
arg: u32,
|
|
|
|
}
|
2020-02-13 15:21:01 +00:00
|
|
|
|
2020-07-07 11:17:36 +00:00
|
|
|
#[test]
|
|
|
|
fn boxed_flatten_subcommand() {
|
2020-02-13 15:21:01 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt {
|
|
|
|
sub: Box::new(Sub::Flame {
|
|
|
|
arg: Box::new(Ext { arg: 1 })
|
|
|
|
})
|
|
|
|
},
|
|
|
|
Opt::parse_from(&["test", "flame", "1"])
|
|
|
|
);
|
|
|
|
}
|
2020-07-07 11:17:36 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn update_boxed_flatten_subcommand() {
|
|
|
|
let mut opt = Opt::parse_from(&["test", "flame", "1"]);
|
|
|
|
|
|
|
|
opt.update_from(&["test", "flame", "42"]);
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
Opt {
|
|
|
|
sub: Box::new(Sub::Flame {
|
|
|
|
arg: Box::new(Ext { arg: 42 })
|
|
|
|
})
|
|
|
|
},
|
|
|
|
opt
|
|
|
|
);
|
|
|
|
}
|