1use clap::{Args, Parser, Subcommand}; 2 3#[derive(Parser, PartialEq, Debug)] 4struct Opt { 5 #[command(subcommand)] 6 sub: Box<Sub>, 7} 8 9#[derive(Subcommand, PartialEq, Debug)] 10enum Sub { 11 Flame { 12 #[command(flatten)] 13 arg: Box<Ext>, 14 }, 15} 16 17#[derive(Args, PartialEq, Debug)] 18struct Ext { 19 arg: u32, 20} 21 22#[test] 23fn 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] 35fn 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