summaryrefslogtreecommitdiff
path: root/src/utils/env.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-23 15:56:13 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-23 15:56:13 +0800
commit5ebd07e52b4ebc1f59b603bbd4fe781871056755 (patch)
tree61e66ef0477d3f61091b8a3cd112b570824a0a23 /src/utils/env.rs
parente011ca752bd4befc73e33c72e59e4e6492ac1aa7 (diff)
Add auto update feature via JV_AUTO_UPDATE env var
When enabled, automatically runs `jv update` if vault content has been modified by local operations.
Diffstat (limited to 'src/utils/env.rs')
-rw-r--r--src/utils/env.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/utils/env.rs b/src/utils/env.rs
index 028995e..5a37365 100644
--- a/src/utils/env.rs
+++ b/src/utils/env.rs
@@ -26,3 +26,24 @@ pub fn current_locales() -> String {
"en".to_string()
}
+
+/// Checks if auto update is enabled based on environment variables.
+///
+/// The function checks the JV_AUTO_UPDATE environment variable and compares
+/// its value (after trimming and converting to lowercase) against known
+/// positive and negative values.
+///
+/// # Returns
+/// `true` if the value matches "yes", "y", or "true"
+/// `false` if the value matches "no", "n", or "false", or if the variable is not set
+pub fn enable_auto_update() -> bool {
+ if let Ok(auto_update) = std::env::var("JV_AUTO_UPDATE") {
+ let normalized = auto_update.trim().to_lowercase();
+ match normalized.as_str() {
+ "yes" | "y" | "true" => return true,
+ "no" | "n" | "false" => return false,
+ _ => {}
+ }
+ }
+ false
+}