@@ -30,7 +30,7 @@ pub struct Diffing {
30
30
#[ clap( subcommand) ]
31
31
pub sub : Option < DiffingMode > ,
32
32
33
- #[ clap( long, short = 'c' ) ]
33
+ #[ clap( global = true , long, short = 'c' ) ]
34
34
pub chip : Vec < String > ,
35
35
36
36
/// Filter by manufacturer, case sensitive, may be combined with other filters
@@ -65,14 +65,23 @@ pub struct Diffing {
65
65
pub use_pager_directly : bool ,
66
66
67
67
#[ clap( last = true ) ]
68
- pub args : Option < String > ,
68
+ pub last_args : Option < String > ,
69
69
}
70
70
71
- #[ derive( clap:: Parser , Debug , Clone , Copy ) ]
71
+ #[ derive( clap:: Parser , Debug , Clone ) ]
72
72
pub enum DiffingMode {
73
- Semver ,
74
- Diff ,
75
- Pr ,
73
+ Semver {
74
+ #[ clap( last = true ) ]
75
+ last_args : Option < String > ,
76
+ } ,
77
+ Diff {
78
+ #[ clap( last = true ) ]
79
+ last_args : Option < String > ,
80
+ } ,
81
+ Pr {
82
+ #[ clap( last = true ) ]
83
+ last_args : Option < String > ,
84
+ } ,
76
85
}
77
86
78
87
impl DiffingMode {
@@ -81,7 +90,7 @@ impl DiffingMode {
81
90
/// [`Pr`]: DiffingMode::Pr
82
91
#[ must_use]
83
92
pub fn is_pr ( & self ) -> bool {
84
- matches ! ( self , Self :: Pr )
93
+ matches ! ( self , Self :: Pr { .. } )
85
94
}
86
95
}
87
96
@@ -93,8 +102,8 @@ impl Diffing {
93
102
let [ baseline, current] = self
94
103
. make_case ( opts)
95
104
. with_context ( || "couldn't setup test case" ) ?;
96
- match self . sub . unwrap_or ( DiffingMode :: Diff ) {
97
- DiffingMode :: Diff | DiffingMode :: Pr => {
105
+ match self . sub . as_ref ( ) {
106
+ None | Some ( DiffingMode :: Diff { .. } | DiffingMode :: Pr { .. } ) => {
98
107
let mut command;
99
108
if let Some ( pager) = & self . pager {
100
109
if self . use_pager_directly {
@@ -118,7 +127,7 @@ impl Diffing {
118
127
. with_context ( || "couldn't run diff" )
119
128
. map ( |_| ( ) )
120
129
}
121
- DiffingMode :: Semver => std:: process:: Command :: new ( "cargo" )
130
+ Some ( DiffingMode :: Semver { .. } ) => std:: process:: Command :: new ( "cargo" )
122
131
. args ( [ "semver-checks" , "check-release" ] )
123
132
. arg ( "--baseline-root" )
124
133
. arg ( baseline. 0 )
@@ -158,7 +167,7 @@ impl Diffing {
158
167
} )
159
168
. filter ( |t| {
160
169
if self . chip . is_empty ( ) {
161
- false
170
+ true
162
171
} else {
163
172
self . chip . iter ( ) . any ( |c| {
164
173
wildmatch:: WildMatch :: new ( & c. to_ascii_lowercase ( ) )
@@ -167,9 +176,9 @@ impl Diffing {
167
176
}
168
177
} )
169
178
. collect :: < Vec < _ > > ( ) ;
170
- let test = match ( tests. len ( ) , self . sub ) {
179
+ let test = match ( tests. len ( ) , self . sub . as_ref ( ) ) {
171
180
( 1 , _) => tests[ 0 ] ,
172
- ( 1 .. , Some ( DiffingMode :: Pr ) ) => tests
181
+ ( _ , Some ( DiffingMode :: Pr { .. } ) ) => tests
173
182
. iter ( )
174
183
. find ( |t| t. chip == "STM32F103" )
175
184
. unwrap_or ( & tests[ 0 ] ) ,
@@ -187,15 +196,34 @@ impl Diffing {
187
196
}
188
197
} ;
189
198
199
+ let last_args = self . last_args . as_deref ( ) . or ( match & self . sub {
200
+ Some (
201
+ DiffingMode :: Diff { last_args }
202
+ | DiffingMode :: Pr { last_args }
203
+ | DiffingMode :: Semver { last_args } ,
204
+ ) => last_args. as_deref ( ) ,
205
+ None => None ,
206
+ } ) ;
207
+ let join = |opt1 : Option < & str > , opt2 : Option < & str > | -> Option < String > {
208
+ match ( opt1, opt2) {
209
+ ( Some ( str1) , Some ( str2) ) => Some ( format ! ( "{} {}" , str1, str2) ) ,
210
+ ( Some ( str) , None ) | ( None , Some ( str) ) => Some ( str. to_owned ( ) ) ,
211
+ ( None , None ) => None ,
212
+ }
213
+ } ;
190
214
let baseline = test
191
215
. setup_case (
192
216
& opts. output_dir . join ( "baseline" ) ,
193
217
& baseline_bin,
194
- baseline_cmd,
218
+ join ( baseline_cmd, last_args ) . as_deref ( ) ,
195
219
)
196
220
. with_context ( || "couldn't create head" ) ?;
197
221
let current = test
198
- . setup_case ( & opts. output_dir . join ( "current" ) , & current_bin, current_cmd)
222
+ . setup_case (
223
+ & opts. output_dir . join ( "current" ) ,
224
+ & current_bin,
225
+ join ( current_cmd, last_args) . as_deref ( ) ,
226
+ )
199
227
. with_context ( || "couldn't create base" ) ?;
200
228
201
229
Ok ( [ baseline, current] )
0 commit comments