use std::{
env::{join_paths, split_paths, var_os},
ffi::{OsStr, OsString},
io,
path::PathBuf,
};
use crate::path::clean::clean_dir_name;
pub fn read_raw_path() -> Option<OsString> {
var_os("PATH")
}
pub fn read_path() -> Vec<PathBuf> {
match read_raw_path() {
Some(path_str) => split_path_like(&path_str),
None => vec![PathBuf::from("")],
}
}
pub fn split_path_like(s: &OsStr) -> Vec<PathBuf> {
split_paths(s)
.into_iter()
.map(|p| clean_dir_name(&p))
.collect()
}
pub fn combine_path_like(dirs: Vec<PathBuf>) -> io::Result<OsString> {
match join_paths(dirs) {
Ok(p) => Ok(p),
Err(e) => Err(io::Error::new(io::ErrorKind::InvalidData, e)),
}
}