From 2f529a3e1c0fae02c046e568c57fd357e5ff9e33 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sun, 2 Nov 2025 22:12:19 +0800 Subject: Add update command to sync from upstream vault The new `jv update` command allows users to synchronize information from the upstream vault when working with a stained workspace. --- src/bin/jv.rs | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) (limited to 'src/bin') diff --git a/src/bin/jv.rs b/src/bin/jv.rs index 95176b5..bd8215a 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -4,7 +4,10 @@ use just_enough_vcs::{ system::action_system::action::ActionContext, utils::{cfg_file::config::ConfigFile, tcp_connection::instance::ConnectionInstance}, vcs::{ - actions::local_actions::SetUpstreamVaultActionResult, + actions::local_actions::{ + SetUpstreamVaultActionResult, UpdateToLatestInfoResult, + proc_update_to_latest_info_action, + }, constants::PORT, current::current_local_path, data::{ @@ -94,6 +97,9 @@ enum JustEnoughVcsWorkspaceCommand { #[command(alias = "in")] Import(ImportFileArgs), + /// Sync information from upstream vault + Update(UpdateArgs), + // Connection management /// Direct to an upstream vault and stain this workspace Direct(DirectArgs), @@ -263,6 +269,13 @@ struct ImportFileArgs { help: bool, } +#[derive(Parser, Debug)] +struct UpdateArgs { + /// Show help information + #[arg(short, long)] + help: bool, +} + #[derive(Parser, Debug)] struct DirectArgs { /// Show help information @@ -433,6 +446,13 @@ async fn main() { } jv_import(import_file_args).await; } + JustEnoughVcsWorkspaceCommand::Update(update_file_args) => { + if update_file_args.help { + println!("{}", md(t!("jv.update"))); + return; + } + jv_update(update_file_args).await; + } JustEnoughVcsWorkspaceCommand::Direct(direct_args) => { if direct_args.help { println!("{}", md(t!("jv.direct"))); @@ -660,6 +680,42 @@ async fn jv_account_move_key(user_dir: UserDirectory, args: MoveKeyToAccountArgs } } +async fn jv_update(_update_file_args: UpdateArgs) { + let Ok(local_config) = LocalConfig::read().await else { + eprintln!("{}", md(t!("jv.fail.read_cfg"))); + return; + }; + + if !local_config.stained() { + eprintln!("{}", md(t!("jv.fail.not_stained"))); + return; + } + + let pool = client_registry::client_action_pool(); + let upstream = local_config.upstream_addr(); + + let Some(instance) = connect(upstream).await else { + return; + }; + + let ctx = ActionContext::local().insert_instance(instance); + + match proc_update_to_latest_info_action(&pool, ctx, ()).await { + Err(e) => handle_err(e), + Ok(result) => match result { + UpdateToLatestInfoResult::Success => { + println!("{}", md(t!("jv.result.update.success"))); + } + UpdateToLatestInfoResult::AuthorizeFailed(e) => { + println!( + "{}", + md(t!("jv.result.direct.directed_and_stained", err = e)) + ) + } + }, + } +} + async fn jv_direct(args: DirectArgs) { if !args.confirm { println!( -- cgit