Skip to content

Commit 15e1d57

Browse files
authored
refactor: command not found error (#58)
1 parent b984191 commit 15e1d57

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
process::exit(c);
1010
}
1111
Err(e) => {
12-
eprintln!("{}", e);
12+
eprintln!("Error: {}", e);
1313
process::exit(1);
1414
}
1515
}
@@ -40,7 +40,12 @@ fn run() -> Result<i32, Box<dyn std::error::Error>> {
4040
return Ok(0);
4141
}
4242
}
43-
let status = Command::new(&cmd_args[0]).args(&cmd_args[1..]).status()?;
43+
let cmd = &cmd_args[0];
44+
let cmd = match which::which(cmd) {
45+
Ok(v) => v,
46+
Err(_) => return Err(format!("Command '{cmd}' not found.").into()),
47+
};
48+
let status = Command::new(cmd).args(&cmd_args[1..]).status()?;
4449

4550
Ok(status.code().unwrap_or_default())
4651
}

0 commit comments

Comments
 (0)