-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(parser): accept non-
false
literals with env vars as true
- Loading branch information
Showing
5 changed files
with
32 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,15 @@ | ||
/// True values are `y`, `yes`, `t`, `true`, `on`, and `1`. | ||
pub(crate) const TRUE_LITERALS: [&str; 6] = ["y", "yes", "t", "true", "on", "1"]; | ||
// pub(crate) const TRUE_LITERALS: [&str; 6] = ["y", "yes", "t", "true", "on", "1"]; | ||
|
||
/// False values are `n`, `no`, `f`, `false`, `off`, and `0`. | ||
pub(crate) const FALSE_LITERALS: [&str; 6] = ["n", "no", "f", "false", "off", "0"]; | ||
const FALSE_LITERALS: [&str; 6] = ["n", "no", "f", "false", "off", "0"]; | ||
|
||
/// Converts a string literal representation of truth to true or false. | ||
/// | ||
/// Translated from the Python function [`strtobool`]. | ||
/// `false` values are `n`, `no`, `f`, `false`, `off`, and `0` (case insensitive). | ||
/// | ||
/// [`strtobool`]: https://docs.python.org/3/distutils/apiref.html#distutils.util.strtobool | ||
/// | ||
/// # Errors | ||
/// Returns Err(val) if `val` is anything else. | ||
pub(crate) fn str_to_bool<S: AsRef<str>>(val: S) -> Result<bool, S> { | ||
/// Any other value will be considered as `true`. | ||
pub(crate) fn str_to_bool(val: impl AsRef<str>) -> bool { | ||
let pat: &str = &val.as_ref().to_lowercase(); | ||
if TRUE_LITERALS.contains(&pat) { | ||
Ok(true) | ||
} else if FALSE_LITERALS.contains(&pat) { | ||
Ok(false) | ||
} else { | ||
Err(val) | ||
} | ||
!FALSE_LITERALS.contains(&pat) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters