mirror of
https://github.com/jht5945/rust_util.git
synced 2025-12-27 07:30:05 +08:00
feat: add env_var
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rust_util"
|
name = "rust_util"
|
||||||
version = "0.6.48"
|
version = "0.6.49"
|
||||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Hatter's Rust Util"
|
description = "Hatter's Rust Util"
|
||||||
|
|||||||
@@ -17,3 +17,15 @@ pub fn is_off(val: &str) -> bool {
|
|||||||
let lower_val = val.to_lowercase();
|
let lower_val = val.to_lowercase();
|
||||||
["false", "no", "0"].iter().any(|x| *x == lower_val)
|
["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
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user