From 6e0c9967d09a3ab8f0c1fcceb91ea9c7a7a800ed Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 19 Mar 2026 15:39:02 +0800 Subject: Make sheetedit and sheetdump accept stdin or file argument --- src/cmds/cmd/sheetdump.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/cmds/cmd/sheetdump.rs') diff --git a/src/cmds/cmd/sheetdump.rs b/src/cmds/cmd/sheetdump.rs index 5877253..badb8fc 100644 --- a/src/cmds/cmd/sheetdump.rs +++ b/src/cmds/cmd/sheetdump.rs @@ -4,8 +4,11 @@ use crate::{ arg::sheetdump::JVSheetdumpArgument, collect::sheetdump::JVSheetdumpCollect, r#in::sheetdump::JVSheetdumpInput, - out::{mappings::JVMappingsOutput, mappings_pretty::JVMappingsPrettyOutput}, + out::{ + mappings::JVMappingsOutput, mappings_pretty::JVMappingsPrettyOutput, none::JVNoneOutput, + }, }, + early_cmd_output, systems::{ cmd::{ cmd_system::{AnyOutput, JVCommandContext}, @@ -38,15 +41,21 @@ async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result Result { +async fn collect(args: &Arg, ctx: &JVCommandContext) -> Result { let mut sheet = SheetData::empty(); - sheet - .full_read(&args.sheet_file) - .await - .map_err(|e| match e { - ReadSheetDataError::IOErr(error) => CmdPrepareError::Io(error), - })?; + let path = match (&args.sheet_file, &ctx.stdin_path) { + (Some(_), Some(stdin)) => stdin, + (Some(file), None) => file, + (None, Some(stdin)) => stdin, + (None, None) => { + return early_cmd_output!(JVNoneOutput => JVNoneOutput); + } + }; + + sheet.full_read(path).await.map_err(|e| match e { + ReadSheetDataError::IOErr(error) => CmdPrepareError::Io(error), + })?; Ok(Collect { sheet: sheet }) } -- cgit