1use crate::checker;
2use std::path::PathBuf;
3use std::process::Command;
4use which::which;
5
6pub fn run_command(
7 file: Option<PathBuf>,
8 manifest: &PathBuf,
9 command: &Vec<String>,
10 show_undeclared: bool,
11 show_missing_optional: bool,
12) {
13 checker::check_command(file, manifest, true, show_undeclared, show_missing_optional);
15 let binary = which(command.get(0).unwrap());
16 if binary.is_err() {
17 eprintln!(
18 "Could not find binary {}. Make sure the program is in your PATH (not an alias)",
19 command.get(0).unwrap()
20 );
21 panic!("{}", binary.unwrap_err());
22 }
23 let binary = binary.unwrap();
24 let other_args = command
25 .iter()
26 .skip(1)
27 .map(|x| x.as_str())
28 .collect::<Vec<&str>>();
29
30 let status = Command::new(binary).args(other_args).status();
32 match status {
33 Ok(code) => {
34 std::process::exit(code.code().unwrap());
35 }
36 Err(e) => {
37 if e.kind() == std::io::ErrorKind::NotFound {
39 eprintln!("{} Make sure the binary is in your PATH (not an alias)", e);
40 std::process::exit(1);
41 } else {
42 panic!("{}", e);
43 }
44 }
45 }
46}