summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-09-03 09:53:42 -0400
committerDan Davison <dandavison7@gmail.com>2020-09-03 09:53:42 -0400
commit2efb9d5c11d29a1ea25c7b8c74f3598dfeffa7a0 (patch)
tree0fe00ea6869045a2dbbb9f3667f7df71d3bfe8c0 /src
parent8f88b5b1eb085cd87f27cc1679b8be17a6719912 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/env.rs8
1 files changed, 2 insertions, 6 deletions
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<String> {
}
}
+/// 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()
}