@@ -27,7 +27,12 @@ fn make() -> clap::Command {
27
27
. about ( "Delete patches" )
28
28
. override_usage ( super :: make_usage (
29
29
"stg delete" ,
30
- & [ "[OPTIONS] <patch>..." , "[OPTIONS] --top" ] ,
30
+ & [
31
+ "[OPTIONS] [<patch>...]" ,
32
+ "[OPTIONS] [-A] [-U] [-H]" ,
33
+ "[OPTIONS] --all" ,
34
+ "[OPTIONS] --top" ,
35
+ ] ,
31
36
) )
32
37
. arg (
33
38
Arg :: new ( "patchranges-all" )
@@ -36,8 +41,51 @@ fn make() -> clap::Command {
36
41
. num_args ( 1 ..)
37
42
. allow_hyphen_values ( true )
38
43
. value_parser ( clap:: value_parser!( PatchRange ) )
39
- . conflicts_with ( "top" )
40
- . required_unless_present ( "top" ) ,
44
+ . conflicts_with_all ( [ "top" , "all" , "A-U-H" ] )
45
+ . required_unless_present_any ( [ "all" , "top" , "A-U-H" ] ) ,
46
+ )
47
+ . arg (
48
+ Arg :: new ( "all" )
49
+ . long ( "all" )
50
+ . short ( 'a' )
51
+ . help ( "Delete all patches" )
52
+ . action ( clap:: ArgAction :: SetTrue )
53
+ . conflicts_with_all ( [ "top" , "A-U-H" , "patchranges-all" ] ) ,
54
+ )
55
+ . arg (
56
+ Arg :: new ( "applied" )
57
+ . long ( "applied" )
58
+ . short ( 'A' )
59
+ . help ( "Delete the applied patches" )
60
+ . action ( clap:: ArgAction :: SetTrue ) ,
61
+ )
62
+ . arg (
63
+ Arg :: new ( "unapplied" )
64
+ . long ( "unapplied" )
65
+ . short ( 'U' )
66
+ . help ( "Delete the unapplied patches" )
67
+ . action ( clap:: ArgAction :: SetTrue ) ,
68
+ )
69
+ . arg (
70
+ Arg :: new ( "hidden" )
71
+ . long ( "hidden" )
72
+ . short ( 'H' )
73
+ . help ( "Delete the hidden patches" )
74
+ . action ( clap:: ArgAction :: SetTrue ) ,
75
+ )
76
+ . group (
77
+ clap:: ArgGroup :: new ( "A-U-H" )
78
+ . multiple ( true )
79
+ . args ( [ "applied" , "unapplied" , "hidden" ] )
80
+ . conflicts_with_all ( [ "top" , "all" , "patchranges-all" ] ) ,
81
+ )
82
+ . arg (
83
+ Arg :: new ( "top" )
84
+ . long ( "top" )
85
+ . short ( 't' )
86
+ . help ( "Delete topmost patch" )
87
+ . action ( clap:: ArgAction :: SetTrue )
88
+ . conflicts_with_all ( [ "all" , "A-U-H" , "patchranges-all" ] ) ,
41
89
)
42
90
. arg (
43
91
Arg :: new ( "spill" )
@@ -53,13 +101,6 @@ fn make() -> clap::Command {
53
101
)
54
102
. action ( clap:: ArgAction :: SetTrue ) ,
55
103
)
56
- . arg (
57
- Arg :: new ( "top" )
58
- . long ( "top" )
59
- . short ( 't' )
60
- . help ( "Delete topmost patch" )
61
- . action ( clap:: ArgAction :: SetTrue ) ,
62
- )
63
104
. arg ( argset:: branch_arg ( ) )
64
105
. arg ( argset:: push_conflicts_arg ( ) )
65
106
}
@@ -79,11 +120,22 @@ fn run(matches: &ArgMatches) -> Result<()> {
79
120
} else {
80
121
return Err ( super :: Error :: NoAppliedPatches . into ( ) ) ;
81
122
}
82
- } else {
83
- let range_specs = matches
84
- . get_many :: < PatchRange > ( "patchranges-all" )
85
- . expect ( "clap will ensure either patches or --top" ) ;
123
+ } else if let Some ( range_specs) = matches. get_many :: < PatchRange > ( "patchranges-all" ) {
86
124
patchrange:: resolve_names ( & stack, range_specs, RangeConstraint :: AllWithAppliedBoundary ) ?
125
+ } else if matches. get_flag ( "all" ) {
126
+ stack. all_patches ( ) . cloned ( ) . collect :: < Vec < _ > > ( )
127
+ } else {
128
+ let mut patches = Vec :: new ( ) ;
129
+ if matches. get_flag ( "applied" ) {
130
+ patches. extend ( stack. applied ( ) . iter ( ) . cloned ( ) )
131
+ }
132
+ if matches. get_flag ( "unapplied" ) {
133
+ patches. extend ( stack. unapplied ( ) . iter ( ) . cloned ( ) )
134
+ }
135
+ if matches. get_flag ( "hidden" ) {
136
+ patches. extend ( stack. hidden ( ) . iter ( ) . cloned ( ) )
137
+ }
138
+ patches
87
139
} ;
88
140
89
141
if spill_flag
0 commit comments