summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scripts/jv_cli.ps15
-rw-r--r--scripts/jv_cli.sh5
-rw-r--r--src/bin/jv.rs8
-rw-r--r--src/utils/env.rs21
4 files changed, 38 insertions, 1 deletions
diff --git a/scripts/jv_cli.ps1 b/scripts/jv_cli.ps1
index 0584c21..b77997c 100644
--- a/scripts/jv_cli.ps1
+++ b/scripts/jv_cli.ps1
@@ -8,6 +8,11 @@ $SCRIPT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition
# Supported: en, zh-CN
# $env:JV_LANG = "en"
+# Use JV_AUTO_UPDATE to set auto content update (yes/no)
+# After local operations that change Upstream Vault content
+# Next `jv` command will auto-run `jv update`
+$env:JV_AUTO_UPDATE = "yes"
+
###############
### ALIASES ###
###############
diff --git a/scripts/jv_cli.sh b/scripts/jv_cli.sh
index 9eb56a9..09b25ab 100644
--- a/scripts/jv_cli.sh
+++ b/scripts/jv_cli.sh
@@ -9,6 +9,11 @@ SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
# Supported: en, zh-CN
# export JV_LANG=en
+# Use JV_AUTO_UPDATE to set auto content update (yes/no)
+# After local operations that change Upstream Vault content
+# Next `jv` command will auto-run `jv update`
+export JV_AUTO_UPDATE=yes
+
###############
### ALIASES ###
###############
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
+}