mirror of
https://github.com/clap-rs/clap
synced 2025-01-10 03:38:50 +00:00
37 lines
649 B
Rust
37 lines
649 B
Rust
|
mod utils;
|
||
|
|
||
|
use clap::{Args, Parser};
|
||
|
|
||
|
#[test]
|
||
|
fn generic() {
|
||
|
#[derive(Args, PartialEq, Debug)]
|
||
|
struct A {
|
||
|
arg: i32,
|
||
|
}
|
||
|
|
||
|
#[derive(Args, PartialEq, Debug)]
|
||
|
struct B {
|
||
|
arg: String,
|
||
|
}
|
||
|
|
||
|
#[derive(Parser, PartialEq, Debug)]
|
||
|
struct Opt<T: Args> {
|
||
|
#[clap(flatten)]
|
||
|
inner: T,
|
||
|
}
|
||
|
assert_eq!(
|
||
|
Opt {
|
||
|
inner: A { arg: 42 }
|
||
|
},
|
||
|
Opt::try_parse_from(&["test", "42"]).unwrap()
|
||
|
);
|
||
|
assert_eq!(
|
||
|
Opt {
|
||
|
inner: B {
|
||
|
arg: "42".to_owned()
|
||
|
}
|
||
|
},
|
||
|
Opt::try_parse_from(&["test", "42"]).unwrap()
|
||
|
);
|
||
|
}
|