use shellexpand;
use std::path::Path;
use std::path::PathBuf;
pub fn validate_path(path: &PathBuf) -> Result<(), String> {
let path_string = path.to_str().unwrap();
if !path.exists() {
let message = format!("the path at {} does not exist", path_string);
Err(message)
} else {
Ok(())
}
}
pub fn deduce_path(filepath: &str) -> Option<&Path> {
let maybe_path = Path::new(filepath);
if !maybe_path.exists() {
None
} else {
Some(maybe_path)
}
}
pub fn expand_path(path: &str) -> Result<String, String> {
let expanded_string_attempt = shellexpand::full(path);
match expanded_string_attempt {
Ok(expanded_string) => Ok(expanded_string.to_string()),
Err(reason) => {
Err(format!("Failed to expand file path {} :\n{}", path, reason))
}
}
}