1
0
mirror of https://github.com/jht5945/rust_util.git synced 2025-12-27 15:40:03 +08:00

feat: add env_var

This commit is contained in:
2025-08-24 16:11:03 +08:00
parent 4b596db8de
commit e2b258ca09
2 changed files with 13 additions and 1 deletions

View File

@@ -17,3 +17,15 @@ pub fn is_off(val: &str) -> bool {
let lower_val = val.to_lowercase();
["false", "no", "0"].iter().any(|x| *x == lower_val)
}
pub fn env_var(var: &str) -> Option<String> {
let var_from_env = env::var(var).ok();
if var_from_env.is_some() {
return var_from_env;
}
let var_content = crate::util_file::read_file_content(&format!("~/.config/envs/{}", var));
if let Ok(var_content) = var_content {
return Some(var_content.trim().to_string());
}
None
}