diff --git a/src/config.rs b/src/config.rs index f712bde..eacb879 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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 { var(key).ok().map_or_else(|| get_setting_from_config(key, &config), Some) }; + let parse = |key: &str| -> Option { + 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() {