Add logging (fix #8)

This commit is contained in:
Roey Darwish Dror
2018-06-17 14:17:36 +03:00
parent 0e2fe028e6
commit b3c8044ad3
6 changed files with 187 additions and 22 deletions

View File

@@ -1,7 +1,10 @@
use failure::Error;
use std::env::home_dir;
use std::ffi::OsStr;
use std::fmt::Debug;
use std::path::{Path, PathBuf};
use std::process::ExitStatus;
use which as which_mod;
#[derive(Fail, Debug)]
#[fail(display = "Process failed")]
@@ -39,3 +42,24 @@ pub fn is_ancestor(ancestor: &Path, path: &Path) -> bool {
false
}
pub fn which<T: AsRef<OsStr> + Debug>(binary_name: T) -> Option<PathBuf> {
match which_mod::which(&binary_name) {
Ok(path) => {
debug!("Detected {:?} as {:?}", &path, &binary_name);
Some(path)
}
Err(e) => {
match e.kind() {
which_mod::ErrorKind::CannotFindBinaryPath => {
debug!("Cannot find {:?}", &binary_name);
}
_ => {
error!("Detecting {:?} failed: {}", &binary_name, e);
}
}
None
}
}
}