@@ -5,15 +5,15 @@ use super::utils;
5
5
#[ test]
6
6
fn subcommand ( ) {
7
7
let m = Command :: new ( "test" )
8
- . subcommand (
9
- Command :: new ( "some" ) . arg (
8
+ . subcommand ( Command :: new ( "some" ) . defer ( |cmd| {
9
+ cmd . arg (
10
10
Arg :: new ( "test" )
11
11
. short ( 't' )
12
12
. long ( "test" )
13
13
. action ( ArgAction :: Set )
14
14
. help ( "testing testing" ) ,
15
- ) ,
16
- )
15
+ )
16
+ } ) )
17
17
. arg ( Arg :: new ( "other" ) . long ( "other" ) )
18
18
. try_get_matches_from ( vec ! [ "myprog" , "some" , "--test" , "testing" ] )
19
19
. unwrap ( ) ;
@@ -30,15 +30,15 @@ fn subcommand() {
30
30
#[ test]
31
31
fn subcommand_none_given ( ) {
32
32
let m = Command :: new ( "test" )
33
- . subcommand (
34
- Command :: new ( "some" ) . arg (
33
+ . subcommand ( Command :: new ( "some" ) . defer ( |cmd| {
34
+ cmd . arg (
35
35
Arg :: new ( "test" )
36
36
. short ( 't' )
37
37
. long ( "test" )
38
38
. action ( ArgAction :: Set )
39
39
. help ( "testing testing" ) ,
40
- ) ,
41
- )
40
+ )
41
+ } ) )
42
42
. arg ( Arg :: new ( "other" ) . long ( "other" ) )
43
43
. try_get_matches_from ( vec ! [ "" ] )
44
44
. unwrap ( ) ;
@@ -50,14 +50,16 @@ fn subcommand_none_given() {
50
50
fn subcommand_multiple ( ) {
51
51
let m = Command :: new ( "test" )
52
52
. subcommands ( vec ! [
53
- Command :: new( "some" ) . arg(
54
- Arg :: new( "test" )
55
- . short( 't' )
56
- . long( "test" )
57
- . action( ArgAction :: Set )
58
- . help( "testing testing" ) ,
59
- ) ,
60
- Command :: new( "add" ) . arg( Arg :: new( "roster" ) . short( 'r' ) ) ,
53
+ Command :: new( "some" ) . defer( |cmd| {
54
+ cmd. arg(
55
+ Arg :: new( "test" )
56
+ . short( 't' )
57
+ . long( "test" )
58
+ . action( ArgAction :: Set )
59
+ . help( "testing testing" ) ,
60
+ )
61
+ } ) ,
62
+ Command :: new( "add" ) . defer( |cmd| cmd. arg( Arg :: new( "roster" ) . short( 'r' ) ) ) ,
61
63
] )
62
64
. arg ( Arg :: new ( "other" ) . long ( "other" ) )
63
65
. try_get_matches_from ( vec ! [ "myprog" , "some" , "--test" , "testing" ] )
@@ -148,8 +150,9 @@ Usage: dym [COMMAND]
148
150
For more information, try '--help'.
149
151
" ;
150
152
151
- let cmd = Command :: new ( "dym" )
152
- . subcommand ( Command :: new ( "subcmd" ) . arg ( arg ! ( -s --subcmdarg <subcmdarg> "tests" ) ) ) ;
153
+ let cmd = Command :: new ( "dym" ) . subcommand (
154
+ Command :: new ( "subcmd" ) . defer ( |cmd| cmd. arg ( arg ! ( -s --subcmdarg <subcmdarg> "tests" ) ) ) ,
155
+ ) ;
153
156
154
157
utils:: assert_output ( cmd, "dym --subcmarg subcmd" , EXPECTED , true ) ;
155
158
}
@@ -166,8 +169,9 @@ Usage: dym [COMMAND]
166
169
For more information, try '--help'.
167
170
" ;
168
171
169
- let cmd = Command :: new ( "dym" )
170
- . subcommand ( Command :: new ( "subcmd" ) . arg ( arg ! ( -s --subcmdarg <subcmdarg> "tests" ) ) ) ;
172
+ let cmd = Command :: new ( "dym" ) . subcommand (
173
+ Command :: new ( "subcmd" ) . defer ( |cmd| cmd. arg ( arg ! ( -s --subcmdarg <subcmdarg> "tests" ) ) ) ,
174
+ ) ;
171
175
172
176
utils:: assert_output ( cmd, "dym --subcmarg foo" , EXPECTED , true ) ;
173
177
}
@@ -427,7 +431,7 @@ fn busybox_like_multicall() {
427
431
}
428
432
let cmd = Command :: new ( "busybox" )
429
433
. multicall ( true )
430
- . subcommand ( Command :: new ( "busybox" ) . subcommands ( applet_commands ( ) ) )
434
+ . subcommand ( Command :: new ( "busybox" ) . defer ( |cmd| cmd . subcommands ( applet_commands ( ) ) ) )
431
435
. subcommands ( applet_commands ( ) ) ;
432
436
433
437
let m = cmd
@@ -553,7 +557,9 @@ Options:
553
557
. version ( "1.0.0" )
554
558
. propagate_version ( true )
555
559
. multicall ( true )
556
- . subcommand ( Command :: new ( "foo" ) . subcommand ( Command :: new ( "bar" ) . arg ( Arg :: new ( "value" ) ) ) ) ;
560
+ . subcommand ( Command :: new ( "foo" ) . defer ( |cmd| {
561
+ cmd. subcommand ( Command :: new ( "bar" ) . defer ( |cmd| cmd. arg ( Arg :: new ( "value" ) ) ) )
562
+ } ) ) ;
557
563
utils:: assert_output ( cmd, "foo bar --help" , EXPECTED , false ) ;
558
564
}
559
565
@@ -573,7 +579,10 @@ Options:
573
579
. version ( "1.0.0" )
574
580
. propagate_version ( true )
575
581
. multicall ( true )
576
- . subcommand ( Command :: new ( "foo" ) . subcommand ( Command :: new ( "bar" ) . arg ( Arg :: new ( "value" ) ) ) ) ;
582
+ . subcommand (
583
+ Command :: new ( "foo" )
584
+ . defer ( |cmd| cmd. subcommand ( Command :: new ( "bar" ) . arg ( Arg :: new ( "value" ) ) ) ) ,
585
+ ) ;
577
586
utils:: assert_output ( cmd, "help foo bar" , EXPECTED , false ) ;
578
587
}
579
588
@@ -593,7 +602,10 @@ Options:
593
602
. version ( "1.0.0" )
594
603
. propagate_version ( true )
595
604
. multicall ( true )
596
- . subcommand ( Command :: new ( "foo" ) . subcommand ( Command :: new ( "bar" ) . arg ( Arg :: new ( "value" ) ) ) ) ;
605
+ . subcommand (
606
+ Command :: new ( "foo" )
607
+ . defer ( |cmd| cmd. subcommand ( Command :: new ( "bar" ) . arg ( Arg :: new ( "value" ) ) ) ) ,
608
+ ) ;
597
609
cmd. build ( ) ;
598
610
let subcmd = cmd. find_subcommand_mut ( "foo" ) . unwrap ( ) ;
599
611
let subcmd = subcmd. find_subcommand_mut ( "bar" ) . unwrap ( ) ;
0 commit comments