From 457b0bd57e641791f67ded489ce2c59682d4d5e2 Mon Sep 17 00:00:00 2001 From: Matthew Esposito Date: Tue, 26 Dec 2023 23:16:36 -0500 Subject: [PATCH] Accept legacy environment variables --- src/config.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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() {