use std::io; use std::path::Path;
use std::process::{Command, Output};
use log::{debug, error};
use crate::errors::{GrabError, GrabResult};
pub(crate) fn run_command(cmd: &str, args: &[&str], current_dir: &Path) -> GrabResult<Output> {
debug!(
"Running command: {} {:?} in directory: {:?}",
cmd, args, current_dir
);
let output = Command::new(cmd)
.args(args)
.current_dir(current_dir) .output()
.map_err(|e| {
let command_string = format!("{} {}", cmd, args.join(" "));
if e.kind() == io::ErrorKind::NotFound {
error!(
"Command '{}' not found. Is '{}' installed and in your system's PATH?",
command_string, cmd
);
}
GrabError::GitExecutionError {
command: command_string,
source: e,
}
})?;
Ok(output)
}