[][src]Function fungus::sys::flag

pub fn flag<K: AsRef<OsStr>>(key: K) -> bool

Get the value of the given environment variable as a flag.

The flag will be considered true if the environment variable is set and the value is any value other than 0 or a case insensitive version of false. The flag will be considered false if the environment variable is unset or it is set and the value is a 0 or a case insensitive version of false.

Examples

use fungus::prelude::*;

// Unset variables will be considered false
assert!(!sys::flag("FOOBAR"));

// Falsy values will be considered `false`
sys::set_var("FOOBAR", "0");
assert!(!sys::flag("FOOBAR"));
sys::set_var("FOOBAR", "false");
assert!(!sys::flag("FOOBAR"));
sys::set_var("FOOBAR", "faLse");
assert!(!sys::flag("FOOBAR"));

// Truthy values will be considered `true`
sys::set_var("FOOBAR", "1");
assert!(sys::flag("FOOBAR"));
sys::set_var("FOOBAR", "BOB");
assert!(sys::flag("FOOBAR"));
sys::set_var("FOOBAR", "True");
assert!(sys::flag("FOOBAR"));