diff options
| author | Dan Davison <dandavison7@gmail.com> | 2020-09-03 09:53:42 -0400 |
|---|---|---|
| committer | Dan Davison <dandavison7@gmail.com> | 2020-09-03 09:53:42 -0400 |
| commit | 2efb9d5c11d29a1ea25c7b8c74f3598dfeffa7a0 (patch) | |
| tree | 0fe00ea6869045a2dbbb9f3667f7df71d3bfe8c0 /src/env.rs | |
| parent | 8f88b5b1eb085cd87f27cc1679b8be17a6719912 (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/env.rs')
| -rw-r--r-- | src/env.rs | 8 |
1 files changed, 2 insertions, 6 deletions
@@ -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() } |
