From 1804e265b4b096bc1c2eb08869e33299ff11e93c Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Nov 2025 17:42:36 +0800 Subject: Add login command combining account setup and vault connection The new `jv login` command streamlines the process of setting up a workspace by combining account selection, vault connection, and initial sync into a single operation. - Add completion support for login command - Update help documentation in both English and Chinese - Add confirmation prompt for login operation --- src/bin/jv.rs | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'src/bin/jv.rs') diff --git a/src/bin/jv.rs b/src/bin/jv.rs index 0fcd7d5..e8e3c64 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -180,6 +180,14 @@ enum JustEnoughVcsWorkspaceCommand { /// Drop a sheet Drop(SheetDropArgs), + + /// As Member, Direct, and Update + #[command(alias = "signin")] + Login(LoginArgs), + + // Completion Helpers + #[command(name = "_ip_history")] + HistoryIpAddress, } #[derive(Parser, Debug)] @@ -301,6 +309,23 @@ struct SheetDropArgs { sheet_name: String, } +#[derive(Parser, Debug)] +struct LoginArgs { + /// Show help information + #[arg(short, long)] + help: bool, + + /// Whether to skip confirmation + #[arg(short = 'C', long)] + confirm: bool, + + /// Member ID + login_member_id: MemberId, + + /// Upstream + upstream: String, +} + #[derive(Parser, Debug)] struct CreateWorkspaceArgs { /// Show help information @@ -860,6 +885,53 @@ async fn main() { JustEnoughVcsWorkspaceCommand::Drop(args) => { jv_sheet_drop(args).await; } + JustEnoughVcsWorkspaceCommand::Login(args) => { + if !args.confirm { + println!( + "{}", + t!( + "jv.confirm.login", + account = args.login_member_id, + upstream = args.upstream + ) + .trim() + .yellow() + ); + confirm_hint_or(t!("common.confirm"), || exit(1)).await; + } + + let user_dir = match UserDirectory::current_doc_dir() { + Some(dir) => dir, + None => { + eprintln!("{}", t!("jv.fail.account.no_user_dir").red()); + return; + } + }; + + jv_account_as( + user_dir, + SetLocalWorkspaceAccountArgs { + help: false, + account_name: args.login_member_id, + }, + ) + .await; + + jv_direct(DirectArgs { + help: false, + upstream: Some(args.upstream.clone()), + confirm: true, + }) + .await; + + jv_update(UpdateArgs { help: false }).await; + } + JustEnoughVcsWorkspaceCommand::HistoryIpAddress => { + get_recent_ip_address() + .await + .iter() + .for_each(|ip| println!("{}", ip)); + } } } -- cgit