1use std::process::Command;
2use std::io::ErrorKind;
3
4
5
6pub fn cmd<F>(program: &'static str, args: F) where F: FnOnce(&mut Command) {
7 let mut cmd = Command::new(program);
8 args(&mut cmd);
9
10 println!("Running {:?}", cmd);
11
12
13
14 let out = cmd.output().unwrap_or_else(|e| {
15 if e.kind() == ErrorKind::NotFound {
16 panic!("Failed to execute command: {}\nIs `{}` not installed?", e, program);
17 }
18
19 panic!("Failed to execute command: {}", e);
20 });
21
22
23 let status = out.status;
24
25 if !status.success() {
26 let log = String::from_utf8(out.stdout).unwrap();
27 let err = String::from_utf8(out.stderr).unwrap();
28 panic!("Command did not executed successfully, got: {}\n-----stdout\n{}\n-----stderr\n{}", status, log, err);
29 }
30}