2022-09-13 12:15:56 +00:00
|
|
|
use clap::Parser;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_safely_nest_parser() {
|
|
|
|
#[derive(Parser, Debug, PartialEq)]
|
|
|
|
struct Opt {
|
|
|
|
#[command(flatten)]
|
|
|
|
foo: Foo,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Parser, Debug, PartialEq)]
|
|
|
|
struct Foo {
|
|
|
|
#[arg(long)]
|
|
|
|
foo: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
Opt {
|
|
|
|
foo: Foo { foo: true }
|
|
|
|
},
|
|
|
|
Opt::try_parse_from(&["test", "--foo"]).unwrap()
|
|
|
|
);
|
|
|
|
}
|
2022-09-30 14:05:48 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn skip_group_avoids_duplicate_ids() {
|
|
|
|
#[derive(Parser, Debug)]
|
|
|
|
struct Opt {
|
|
|
|
#[command(flatten)]
|
|
|
|
first: Compose<Empty, Empty>,
|
|
|
|
#[command(flatten)]
|
|
|
|
second: Compose<Empty, Empty>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(clap::Args, Debug)]
|
2022-09-30 14:13:38 +00:00
|
|
|
#[group(skip)]
|
2022-09-30 14:05:48 +00:00
|
|
|
pub struct Compose<L: clap::Args, R: clap::Args> {
|
|
|
|
#[clap(flatten)]
|
|
|
|
pub left: L,
|
|
|
|
#[clap(flatten)]
|
|
|
|
pub right: R,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(clap::Args, Clone, Copy, Debug)]
|
2022-09-30 14:13:38 +00:00
|
|
|
#[group(skip)]
|
2022-09-30 14:05:48 +00:00
|
|
|
pub struct Empty;
|
|
|
|
|
|
|
|
use clap::CommandFactory;
|
|
|
|
Opt::command().debug_assert();
|
|
|
|
}
|