use std::path::PathBuf;
#[must_use]
#[derive(Copy, Clone, Debug)]
pub struct ExitCode(pub isize);
impl ExitCode {
pub fn is_success(&self) -> bool {
match self {
ExitCode(0) => true,
ExitCode(_) => false,
}
}
}
pub fn get_from_path(exe_name: &str) -> Option<PathBuf> {
std::env::var_os("PATH").and_then(|paths| {
std::env::split_paths(&paths).find_map(|dir| {
let bash_path = dir.join(exe_name);
if bash_path.is_file() {
Some(bash_path)
} else {
None
}
})
})
}
pub fn get_sh() -> Option<PathBuf> {
let exe_name = if cfg!(target_os = "windows") {
"bash.exe"
} else {
"sh"
};
if cfg!(target_os = "windows") {
let git_path = get_from_path("git.exe").expect("Couldn't find git.exe");
let git_dir = git_path.parent().unwrap().parent().unwrap();
let git_bash = git_dir.join("bin").join(exe_name);
if git_bash.is_file() {
return Some(git_bash);
}
}
get_from_path(exe_name)
}