1
1
use std:: fs:: File ;
2
- use std:: io:: { BufRead , BufReader , BufWriter , Write } ;
2
+ use std:: io:: { BufRead , BufReader , BufWriter , Cursor , Write } ;
3
3
use std:: process:: { Command , Stdio } ;
4
4
5
5
use anyhow:: { Context , Result } ;
@@ -12,21 +12,27 @@ const VENDORPATH: &str = "target/vendor.tar.zstd";
12
12
13
13
fn main ( ) {
14
14
if let Err ( e) = try_main ( ) {
15
- eprintln ! ( "{e:?}" ) ;
15
+ eprintln ! ( "error: {e:?}" ) ;
16
16
std:: process:: exit ( 1 ) ;
17
17
}
18
18
}
19
19
20
+ #[ allow( clippy:: type_complexity) ]
21
+ const TASKS : & [ ( & str , fn ( & Shell ) -> Result < ( ) > ) ] = & [
22
+ ( "vendor" , vendor) ,
23
+ ( "package" , package) ,
24
+ ( "package-srpm" , package_srpm) ,
25
+ ( "custom-lints" , custom_lints) ,
26
+ ] ;
27
+
20
28
fn try_main ( ) -> Result < ( ) > {
21
29
let task = std:: env:: args ( ) . nth ( 1 ) ;
22
30
let sh = xshell:: Shell :: new ( ) ?;
23
31
if let Some ( cmd) = task. as_deref ( ) {
24
- let f = match cmd {
25
- "vendor" => vendor,
26
- "package" => package,
27
- "package-srpm" => package_srpm,
28
- _ => print_help,
29
- } ;
32
+ let f = TASKS
33
+ . iter ( )
34
+ . find_map ( |( k, f) | ( * k == cmd) . then_some ( * f) )
35
+ . unwrap_or ( print_help) ;
30
36
f ( & sh) ?;
31
37
} else {
32
38
print_help ( & sh) ?;
@@ -166,11 +172,22 @@ fn package_srpm(sh: &Shell) -> Result<()> {
166
172
Ok ( ( ) )
167
173
}
168
174
175
+ fn custom_lints ( sh : & Shell ) -> Result < ( ) > {
176
+ // Verify there are no invocations of the dbg macro.
177
+ let o = cmd ! ( sh, "git grep dbg\x21 *.rs" ) . ignore_status ( ) . read ( ) ?;
178
+ if !o. is_empty ( ) {
179
+ let mut stderr = std:: io:: stderr ( ) . lock ( ) ;
180
+ std:: io:: copy ( & mut Cursor :: new ( o. as_bytes ( ) ) , & mut stderr) ?;
181
+ eprintln ! ( ) ;
182
+ anyhow:: bail!( "Found dbg\x21 macro" ) ;
183
+ }
184
+ Ok ( ( ) )
185
+ }
186
+
169
187
fn print_help ( _sh : & Shell ) -> Result < ( ) > {
170
- eprintln ! (
171
- "Tasks:
172
- - vendor
173
- "
174
- ) ;
188
+ println ! ( "Tasks:" ) ;
189
+ for ( name, _) in TASKS {
190
+ println ! ( " - {name}" ) ;
191
+ }
175
192
Ok ( ( ) )
176
193
}
0 commit comments