From 2efb9d5c11d29a1ea25c7b8c74f3598dfeffa7a0 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Thu, 3 Sep 2020 09:53:42 -0400 Subject: Interpret an env var as boolean false iff it is unset If it is set to any value, including "" (and of course "false") then it is true. This matches the semantics which clap seems likely to adopt: https://github.com/clap-rs/clap/issues/1476#issuecomment-652344026 --- src/env.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/env.rs') diff --git a/src/env.rs b/src/env.rs index dc30ecc..0a988f9 100644 --- a/src/env.rs +++ b/src/env.rs @@ -9,11 +9,7 @@ pub fn get_env_var(name: &str) -> Option { } } +/// If `name` is set to any value at all (including "") then return true; else false. pub fn get_boolean_env_var(name: &str) -> bool { - let val = get_env_var(name).map(|s| s.to_lowercase()); - match val.as_deref() { - None => false, - Some("false") => false, - Some(_) => true, - } + env::var(name).ok().is_some() } -- cgit v1.2.3