summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/jv.rs8
-rw-r--r--src/utils/env.rs21
2 files changed, 28 insertions, 1 deletions
diff --git a/src/bin/jv.rs b/src/bin/jv.rs
index e71b6d6..773af96 100644
--- a/src/bin/jv.rs
+++ b/src/bin/jv.rs
@@ -33,6 +33,7 @@ use just_enough_vcs::{
LocalWorkspace, align::AlignTasks, cached_sheet::CachedSheet, config::LocalConfig,
file_status::AnalyzeResult, latest_file_data::LatestFileData,
latest_info::LatestInfo, local_files::get_relative_paths,
+ vault_modified::check_vault_modified,
},
member::{Member, MemberId},
user::UserDirectory,
@@ -62,7 +63,7 @@ use just_enough_vcs_cli::{
},
utils::{
display::{SimpleTable, md, size_str},
- env::current_locales,
+ env::{current_locales, enable_auto_update},
fs::move_across_partitions,
input::{confirm_hint, confirm_hint_or, input_with_editor, show_in_pager},
socket_addr_helper,
@@ -604,6 +605,11 @@ async fn main() {
#[cfg(windows)]
colored::control::set_virtual_terminal(true).unwrap();
+ // Auto update
+ if enable_auto_update() && check_vault_modified().await {
+ jv_update(UpdateArgs { help: false }).await;
+ }
+
let Ok(parser) = JustEnoughVcsWorkspace::try_parse() else {
eprintln!("{}", md(t!("jv.fail.parse.parser_failed")));
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
+}