summaryrefslogtreecommitdiff
path: root/src/cmds/cmd/sheetdump.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-03-19 15:39:02 +0800
committer魏曹先生 <1992414357@qq.com>2026-03-19 15:39:02 +0800
commit6e0c9967d09a3ab8f0c1fcceb91ea9c7a7a800ed (patch)
tree081aab1f329ecff906d71f1091ff6540f0da63a7 /src/cmds/cmd/sheetdump.rs
parent6e7781a62c00b4329e15d9aba365afff4b601128 (diff)
Make sheetedit and sheetdump accept stdin or file argument
Diffstat (limited to 'src/cmds/cmd/sheetdump.rs')
-rw-r--r--src/cmds/cmd/sheetdump.rs25
1 files changed, 17 insertions, 8 deletions
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<In, CmdPrepareEr
})
}
-async fn collect(args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {
+async fn collect(args: &Arg, ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {
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 })
}