From f9fa7d65d775959efbc9609ccafd1fdce76129e4 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 23 Jan 2026 09:42:09 +0800 Subject: Add localization and refactor status command output --- src/cmds/status.rs | 98 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 87 insertions(+), 11 deletions(-) (limited to 'src/cmds/status.rs') diff --git a/src/cmds/status.rs b/src/cmds/status.rs index 8279e50..54e033e 100644 --- a/src/cmds/status.rs +++ b/src/cmds/status.rs @@ -1,8 +1,11 @@ use std::time::SystemTime; +use just_enough_vcs::vcs::constants::VAULT_HOST_NAME; + use crate::{ arguments::status::JVStatusArgument, - outputs::status::JVStatusResult, + inputs::status::JVStatusInput, + outputs::status::{JVStatusOutput, JVStatusWrongModifyReason}, renderers::status::JVStatusRenderer, systems::cmd::{ cmd_system::{JVCommand, JVCommandContext}, @@ -13,16 +16,16 @@ use crate::{ pub struct JVStatusCommand; -impl JVCommand +impl JVCommand for JVStatusCommand { async fn prepare( _args: JVStatusArgument, _ctx: JVCommandContext, - ) -> Result { + ) -> Result { // Initialize a reader for the local workspace and a default result structure let mut reader = LocalWorkspaceReader::default(); - let mut input = JVStatusResult::default(); + let mut input = JVStatusInput::default(); // Analyze the current status of the local workspace // (detects changes like created, modified, moved, etc.) @@ -34,6 +37,16 @@ impl JVCommand Result { - Ok(input) // Analyze command, no needs execute + async fn exec(mut input: JVStatusInput) -> Result { + let latest_file_data = &input.latest_file_data; + + // Calculate whether modifications are correc + let modified = &input.analyzed_result.modified; + for item in modified { + // Get mapping + let Ok(mapping) = input.local_sheet_data.mapping_data(&item) else { + continue; + }; + + // Check base version + { + let base_version = mapping.version_when_updated().clone(); + let Some(latest_version) = latest_file_data + .file_version(mapping.mapping_vfid()) + .cloned() + else { + continue; + }; + + // Base version dismatch + if base_version != latest_version { + input.wrong_modified_items.insert( + item.clone(), + JVStatusWrongModifyReason::BaseVersionMismatch { + base_version, + latest_version, + }, + ); + continue; + } + } + + // Check edit right (only check when current is not HOST) + if input.current_account != VAULT_HOST_NAME { + let holder = latest_file_data.file_holder(mapping.mapping_vfid()); + if holder.is_none() { + input + .wrong_modified_items + .insert(item.clone(), JVStatusWrongModifyReason::NoHolder); + continue; + } + + let holder = holder.cloned().unwrap(); + if &input.current_account != &holder { + input.wrong_modified_items.insert( + item.clone(), + JVStatusWrongModifyReason::ModifiedButNotHeld { holder: holder }, + ); + } + } + } + + let output = JVStatusOutput { + current_account: input.current_account, + current_sheet: input.current_sheet, + is_host_mode: input.is_host_mode, + in_ref_sheet: input.in_ref_sheet, + analyzed_result: input.analyzed_result, + wrong_modified_items: input.wrong_modified_items, + update_time: input.update_time, + now_time: input.now_time, + }; + + Ok(output) } fn get_help_str() -> String { -- cgit