Skip to content

Commit 7676574

Browse files
committed
xtask: Clean up CLI dispatch
Tempting to use clap, but it's heavyweight... Signed-off-by: Colin Walters <[email protected]>
1 parent a291e5b commit 7676574

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

xtask/src/xtask.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@ fn main() {
1717
}
1818
}
1919

20+
const TASKS: &[(&'static str, fn(&Shell) -> Result<()>)] = &[
21+
("vendor", vendor),
22+
("package", package),
23+
("package-srpm", package_srpm),
24+
];
25+
2026
fn try_main() -> Result<()> {
2127
let task = std::env::args().nth(1);
2228
let sh = xshell::Shell::new()?;
2329
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);
3034
f(&sh)?;
3135
} else {
3236
print_help(&sh)?;
@@ -167,10 +171,9 @@ fn package_srpm(sh: &Shell) -> Result<()> {
167171
}
168172

169173
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+
}
175178
Ok(())
176179
}

0 commit comments

Comments
 (0)