@@ -74,10 +74,47 @@ pub struct Tests {
74
74
/// Print all available test using the specified filters
75
75
#[ clap( long) ]
76
76
pub list : bool ,
77
+
78
+ /// Path to an `svd2rust` binary, relative or absolute.
79
+ /// Defaults to `target/release/svd2rust[.exe]` of this repository
80
+ /// (which must be already built)
81
+ #[ clap( short = 'p' , long = "svd2rust-path" , default_value = default_svd2rust( ) ) ]
82
+ pub current_bin_path : PathBuf ,
77
83
// TODO: Specify smaller subset of tests? Maybe with tags?
78
84
// TODO: Compile svd2rust?
79
85
}
80
86
87
+ #[ derive( clap:: Parser , Debug ) ]
88
+ #[ clap( name = "diff" ) ]
89
+ pub struct Diffing {
90
+ #[ clap( long) ]
91
+ pub base : Option < String > ,
92
+
93
+ #[ clap( long) ]
94
+ pub head : Option < String > ,
95
+
96
+ /// Enable formatting with `rustfmt`
97
+ #[ clap( short = 'f' , long) ]
98
+ pub format : bool ,
99
+
100
+ #[ clap( subcommand) ]
101
+ pub short : Option < DiffingSub > ,
102
+ }
103
+
104
+ #[ derive( clap:: Parser , Debug ) ]
105
+ pub enum DiffingSub {
106
+ Pr
107
+ }
108
+
109
+ #[ test]
110
+ pub fn diffing_cli_works ( ) {
111
+ Diffing :: parse_from ( [ "diff" , "pr" ] ) ;
112
+ Diffing :: parse_from ( [ "diff" , "--base" , "" , "--head" , "\" --atomics\" " ] ) ;
113
+ Diffing :: parse_from ( [ "diff" , "--base" , "\" @master\" " , "--head" , "\" @pr\" " ] ) ;
114
+ Diffing :: parse_from ( [ "diff" , "--base" , "\" @master\" " , "--head" , "\" @pr --atomics\" " ] ) ;
115
+ Diffing :: parse_from ( [ "diff" , "--head" , "\" --atomics\" " ] ) ;
116
+ }
117
+
81
118
impl Tests {
82
119
fn run (
83
120
& self ,
@@ -192,6 +229,7 @@ impl Tests {
192
229
193
230
#[ derive( clap:: Subcommand , Debug ) ]
194
231
pub enum Subcommand {
232
+ Diff ( Diffing ) ,
195
233
Tests ( Tests ) ,
196
234
}
197
235
@@ -202,12 +240,6 @@ pub struct Opts {
202
240
#[ clap( global = true , long, short = 'v' , action = clap:: ArgAction :: Count ) ]
203
241
pub verbose : u8 ,
204
242
205
- /// Path to an `svd2rust` binary, relative or absolute.
206
- /// Defaults to `target/release/svd2rust[.exe]` of this repository
207
- /// (which must be already built)
208
- #[ clap( global = true , short = 'p' , long = "svd2rust-path" , default_value = default_svd2rust( ) ) ]
209
- pub current_bin_path : PathBuf ,
210
-
211
243
/// Path to an `rustfmt` binary, relative or absolute.
212
244
/// Defaults to `$(rustup which rustfmt)`
213
245
#[ clap( global = true , long) ]
@@ -228,6 +260,7 @@ impl Opts {
228
260
fn use_rustfmt ( & self ) -> bool {
229
261
match self . subcommand {
230
262
Subcommand :: Tests ( Tests { format, .. } ) => format,
263
+ Subcommand :: Diff ( Diffing { format, .. } ) => format,
231
264
}
232
265
}
233
266
}
@@ -344,11 +377,14 @@ fn main() -> Result<(), anyhow::Error> {
344
377
match & opt. subcommand {
345
378
Subcommand :: Tests ( tests_opts) => {
346
379
anyhow:: ensure!(
347
- opt . current_bin_path. exists( ) ,
380
+ tests_opts . current_bin_path. exists( ) ,
348
381
"svd2rust binary does not exist"
349
382
) ;
350
383
351
- tests_opts. run ( & opt, & opt. current_bin_path , rustfmt_bin_path) ?
384
+ tests_opts. run ( & opt, & tests_opts. current_bin_path , rustfmt_bin_path) ?
385
+ }
386
+ Subcommand :: Diff ( _diff) => {
387
+ todo ! ( )
352
388
}
353
389
}
354
390
}
0 commit comments