use super::errors::*;
use std::ffi::OsStr;
use std::path::Path;
use std::process::{Command, ExitStatus, Stdio};
pub fn execute(arg: impl AsRef<OsStr>, dir: impl AsRef<Path>) -> Result<ExitStatus> {
let mut command = Command::new(get_shell_command());
let mut child = command
.args(get_shell_args())
.arg(arg)
.current_dir(dir)
.stdin(Stdio::inherit())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.spawn()
.map_err(|e| err_command_spawn(e.to_string()))?;
Ok(child.wait().expect("failed to wait for child process"))
}
#[cfg(target_os = "macos")]
fn get_shell_command() -> &'static str {
"/bin/zsh"
}
#[cfg(target_os = "linux")]
fn get_shell_command() -> &'static str {
"/bin/sh"
}
#[cfg(target_os = "windows")]
fn get_shell_command() -> &'static str {
"cmd"
}
#[cfg(unix)]
fn get_shell_args() -> &'static [&'static str] {
&["-c"]
}
#[cfg(target_os = "windows")]
fn get_shell_args() -> &'static [&'static str] {
&["/c"]
}