File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change @@ -17,16 +17,20 @@ fn main() {
17
17
}
18
18
}
19
19
20
+ const TASKS : & [ ( & ' static str , fn ( & Shell ) -> Result < ( ) > ) ] = & [
21
+ ( "vendor" , vendor) ,
22
+ ( "package" , package) ,
23
+ ( "package-srpm" , package_srpm) ,
24
+ ] ;
25
+
20
26
fn try_main ( ) -> Result < ( ) > {
21
27
let task = std:: env:: args ( ) . nth ( 1 ) ;
22
28
let sh = xshell:: Shell :: new ( ) ?;
23
29
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
- } ;
30
+ let f = TASKS
31
+ . into_iter ( )
32
+ . find_map ( |( k, f) | ( * k == cmd) . then_some ( * f) )
33
+ . unwrap_or ( print_help) ;
30
34
f ( & sh) ?;
31
35
} else {
32
36
print_help ( & sh) ?;
@@ -167,10 +171,9 @@ fn package_srpm(sh: &Shell) -> Result<()> {
167
171
}
168
172
169
173
fn print_help ( _sh : & Shell ) -> Result < ( ) > {
170
- eprintln ! (
171
- "Tasks:
172
- - vendor
173
- "
174
- ) ;
174
+ println ! ( "Tasks:" ) ;
175
+ for ( name, _) in TASKS {
176
+ println ! ( " - {name}" ) ;
177
+ }
175
178
Ok ( ( ) )
176
179
}
You can’t perform that action at this time.
0 commit comments