@@ -30,7 +30,7 @@ pub struct Diffing {
3030 #[ clap( subcommand) ]
3131 pub sub : Option < DiffingMode > ,
3232
33- #[ clap( long, short = 'c' ) ]
33+ #[ clap( global = true , long, short = 'c' ) ]
3434 pub chip : Vec < String > ,
3535
3636 /// Filter by manufacturer, case sensitive, may be combined with other filters
@@ -65,14 +65,23 @@ pub struct Diffing {
6565 pub use_pager_directly : bool ,
6666
6767 #[ clap( last = true ) ]
68- pub args : Option < String > ,
68+ pub last_args : Option < String > ,
6969}
7070
71- #[ derive( clap:: Parser , Debug , Clone , Copy ) ]
71+ #[ derive( clap:: Parser , Debug , Clone ) ]
7272pub 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+ } ,
7685}
7786
7887impl DiffingMode {
@@ -81,7 +90,7 @@ impl DiffingMode {
8190 /// [`Pr`]: DiffingMode::Pr
8291 #[ must_use]
8392 pub fn is_pr ( & self ) -> bool {
84- matches ! ( self , Self :: Pr )
93+ matches ! ( self , Self :: Pr { .. } )
8594 }
8695}
8796
@@ -93,8 +102,8 @@ impl Diffing {
93102 let [ baseline, current] = self
94103 . make_case ( opts)
95104 . 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 { .. } ) => {
98107 let mut command;
99108 if let Some ( pager) = & self . pager {
100109 if self . use_pager_directly {
@@ -118,7 +127,7 @@ impl Diffing {
118127 . with_context ( || "couldn't run diff" )
119128 . map ( |_| ( ) )
120129 }
121- DiffingMode :: Semver => std:: process:: Command :: new ( "cargo" )
130+ Some ( DiffingMode :: Semver { .. } ) => std:: process:: Command :: new ( "cargo" )
122131 . args ( [ "semver-checks" , "check-release" ] )
123132 . arg ( "--baseline-root" )
124133 . arg ( baseline. 0 )
@@ -158,7 +167,8 @@ impl Diffing {
158167 } )
159168 . filter ( |t| {
160169 if self . chip . is_empty ( ) {
161- false
170+ // this is different from the tests command, which defaults to all chips = false
171+ true
162172 } else {
163173 self . chip . iter ( ) . any ( |c| {
164174 wildmatch:: WildMatch :: new ( & c. to_ascii_lowercase ( ) )
@@ -167,9 +177,9 @@ impl Diffing {
167177 }
168178 } )
169179 . collect :: < Vec < _ > > ( ) ;
170- let test = match ( tests. len ( ) , self . sub ) {
180+ let test = match ( tests. len ( ) , self . sub . as_ref ( ) ) {
171181 ( 1 , _) => tests[ 0 ] ,
172- ( 1 .. , Some ( DiffingMode :: Pr ) ) => tests
182+ ( _ , Some ( DiffingMode :: Pr { .. } ) ) => tests
173183 . iter ( )
174184 . find ( |t| t. chip == "STM32F103" )
175185 . unwrap_or ( & tests[ 0 ] ) ,
@@ -187,15 +197,34 @@ impl Diffing {
187197 }
188198 } ;
189199
200+ let last_args = self . last_args . as_deref ( ) . or ( match & self . sub {
201+ Some (
202+ DiffingMode :: Diff { last_args }
203+ | DiffingMode :: Pr { last_args }
204+ | DiffingMode :: Semver { last_args } ,
205+ ) => last_args. as_deref ( ) ,
206+ None => None ,
207+ } ) ;
208+ let join = |opt1 : Option < & str > , opt2 : Option < & str > | -> Option < String > {
209+ match ( opt1, opt2) {
210+ ( Some ( str1) , Some ( str2) ) => Some ( format ! ( "{} {}" , str1, str2) ) ,
211+ ( Some ( str) , None ) | ( None , Some ( str) ) => Some ( str. to_owned ( ) ) ,
212+ ( None , None ) => None ,
213+ }
214+ } ;
190215 let baseline = test
191216 . setup_case (
192217 & opts. output_dir . join ( "baseline" ) ,
193218 & baseline_bin,
194- baseline_cmd,
219+ join ( baseline_cmd, last_args ) . as_deref ( ) ,
195220 )
196221 . with_context ( || "couldn't create head" ) ?;
197222 let current = test
198- . setup_case ( & opts. output_dir . join ( "current" ) , & current_bin, current_cmd)
223+ . setup_case (
224+ & opts. output_dir . join ( "current" ) ,
225+ & current_bin,
226+ join ( current_cmd, last_args) . as_deref ( ) ,
227+ )
199228 . with_context ( || "couldn't create base" ) ?;
200229
201230 Ok ( [ baseline, current] )
0 commit comments