summaryrefslogtreecommitdiffstats
path: root/src/env.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-09-03 09:51:32 -0400
committerDan Davison <dandavison7@gmail.com>2020-09-03 09:51:32 -0400
commit8f88b5b1eb085cd87f27cc1679b8be17a6719912 (patch)
treec22813b8db24626494471fb81da83c0161bfb430 /src/env.rs
parentba6535ea4169128f35c478bf30b409bd3f9d0673 (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.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/env.rs b/src/env.rs
index 70811353..dc30ecca 100644
--- a/src/env.rs
+++ b/src/env.rs
@@ -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,
+ }
+}