clap/tests/derive/groups.rs
2022-09-30 09:05:48 -05:00

49 lines
1,020 B
Rust

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()
);
}
#[test]
#[should_panic = "'Compose' is already in use"]
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)]
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)]
pub struct Empty;
use clap::CommandFactory;
Opt::command().debug_assert();
}