#[has_command]
Expand description
Macro to test if host system has a command
use has_command::has_command;
use std::process::Command;
fn main() {
run_ls();
run_not_a_command();
run_multiple();
}
#[has_command(ls)]
fn run_ls() {
Command::new("ls").output().expect("Error running ls");
}
#[has_command(not-a-command)]
fn run_not_a_command() {
assert!(false);
}
#[has_command(ls)]
#[has_command(ps)]
#[has_command(cat)]
fn run_multiple() {
assert!(Command::new("ls").output().expect("Error running ls").status.success());
assert!(Command::new("ps").output().expect("Error running ps").status.success());
assert!(Command::new("not-a-command").output().is_err());
assert!(!Command::new("cat").arg("not-a-file").output().expect("Error running cat").status.success());
}