• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use clap::{Args, Parser, Subcommand};
2 
3 #[derive(Parser, PartialEq, Debug)]
4 struct Opt {
5     #[command(subcommand)]
6     sub: Box<Sub>,
7 }
8 
9 #[derive(Subcommand, PartialEq, Debug)]
10 enum Sub {
11     Flame {
12         #[command(flatten)]
13         arg: Box<Ext>,
14     },
15 }
16 
17 #[derive(Args, PartialEq, Debug)]
18 struct Ext {
19     arg: u32,
20 }
21 
22 #[test]
boxed_flatten_subcommand()23 fn boxed_flatten_subcommand() {
24     assert_eq!(
25         Opt {
26             sub: Box::new(Sub::Flame {
27                 arg: Box::new(Ext { arg: 1 })
28             })
29         },
30         Opt::try_parse_from(["test", "flame", "1"]).unwrap()
31     );
32 }
33 
34 #[test]
update_boxed_flatten_subcommand()35 fn update_boxed_flatten_subcommand() {
36     let mut opt = Opt::try_parse_from(["test", "flame", "1"]).unwrap();
37 
38     opt.try_update_from(["test", "flame", "42"]).unwrap();
39 
40     assert_eq!(
41         Opt {
42             sub: Box::new(Sub::Flame {
43                 arg: Box::new(Ext { arg: 42 })
44             })
45         },
46         opt
47     );
48 }
49