diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-09-03 09:51:32 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-09-03 09:51:32 -0400 |
commit | 8f88b5b1eb085cd87f27cc1679b8be17a6719912 (patch) | |
tree | c22813b8db24626494471fb81da83c0161bfb430 /src/env.rs | |
parent | ba6535ea4169128f35c478bf30b409bd3f9d0673 (diff) |
Hack: env var for boolean flag
The proper way would be using env = "DELTA_NAVIGATE", but see
https://github.com/clap-rs/clap/issues/1476
https://github.com/TeXitoi/structopt/issues/372
Doing it as in this commit probably has drawbacks, e.g. related to
whether the argument is recorded as having been supplied.
Diffstat (limited to 'src/env.rs')
-rw-r--r-- | src/env.rs | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -8,3 +8,12 @@ pub fn get_env_var(name: &str) -> Option<String> { non_empty_string => Some(non_empty_string.to_string()), } } + +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, + } +} |