Accept y/n, True/False, 1/0 as booleans in environment vars

This commit is contained in:
Daniel García
2020-01-20 22:28:54 +01:00
parent 84ed185579
commit d212dfe735
2 changed files with 19 additions and 4 deletions

View File

@ -309,6 +309,17 @@ where
try_parse_string(env::var(key))
}
const TRUE_VALUES: &[&str] = &["true", "t", "yes", "y", "1"];
const FALSE_VALUES: &[&str] = &["false", "f", "no", "n", "0"];
pub fn get_env_bool(key: &str) -> Option<bool> {
match env::var(key) {
Ok(val) if TRUE_VALUES.contains(&val.to_lowercase().as_ref()) => Some(true),
Ok(val) if FALSE_VALUES.contains(&val.to_lowercase().as_ref()) => Some(false),
_ => None,
}
}
//
// Date util methods
//