Accept legacy environment variables
This commit is contained in:
parent
47822d8d6c
commit
457b0bd57e
@ -89,7 +89,12 @@ impl Config {
|
||||
// This function defines the order of preference - first check for
|
||||
// environment variables with "REDLIB", then check the config, then if
|
||||
// both are `None`, return a `None` via the `map_or_else` function
|
||||
let parse = |key: &str| -> Option<String> { var(key).ok().map_or_else(|| get_setting_from_config(key, &config), Some) };
|
||||
let parse = |key: &str| -> Option<String> {
|
||||
var(key).ok().map_or_else(
|
||||
|| var(key.replace("REDLIB_", "LIBREDDIT_")).ok().map_or_else(|| get_setting_from_config(key, &config), Some),
|
||||
Some,
|
||||
)
|
||||
};
|
||||
|
||||
Self {
|
||||
sfw_only: parse("REDLIB_SFW_ONLY"),
|
||||
@ -169,6 +174,12 @@ fn test_config() {
|
||||
assert_eq!(get_setting("REDLIB_DEFAULT_COMMENT_SORT"), Some("best".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[sealed_test(env = [("LIBREDDIT_SFW_ONLY", "on")])]
|
||||
fn test_env_var_legacy() {
|
||||
assert!(crate::utils::sfw_only())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[sealed_test(env = [("REDLIB_DEFAULT_COMMENT_SORT", "top")])]
|
||||
fn test_env_config_precedence() {
|
||||
|
Loading…
Reference in New Issue
Block a user