diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-18 22:49:50 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-18 22:49:50 +0800 |
| commit | 5372793a49567dcba7315bf8e7bc5a1cab2d5a76 (patch) | |
| tree | 96d13d527835c23b978eae470e54a1d5fd15bc6d /src/cmds/cmd/hexdump.rs | |
| parent | 2609dfe338b9bace6ff74c5efc93f684ba55a44e (diff) | |
Add support for reading from stdin and improve error messages
Diffstat (limited to 'src/cmds/cmd/hexdump.rs')
| -rw-r--r-- | src/cmds/cmd/hexdump.rs | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/cmds/cmd/hexdump.rs b/src/cmds/cmd/hexdump.rs index 346fffe..34df45c 100644 --- a/src/cmds/cmd/hexdump.rs +++ b/src/cmds/cmd/hexdump.rs @@ -1,9 +1,12 @@ use crate::{ cmd_output, cmds::{ - arg::single_file::JVSingleFileArgument, collect::single_file::JVSingleFileCollect, - r#in::empty::JVEmptyInput, out::hex::JVHexOutput, + arg::single_file::JVSingleFileArgument, + collect::single_file::JVSingleFileCollect, + r#in::empty::JVEmptyInput, + out::{hex::JVHexOutput, none::JVNoneOutput}, }, + early_cmd_output, systems::{ cmd::{ cmd_system::{AnyOutput, JVCommandContext}, @@ -30,9 +33,17 @@ async fn prepare(_args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareE Ok(In {}) } -async fn collect(args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> { - let file = &args.file; - let data = fs::read(file).await?; +async fn collect(args: &Arg, ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> { + let data = if let Some(ref stdin_path) = ctx.stdin_path { + fs::read(stdin_path).await? + } else if let Some(ref stdin_data) = ctx.stdin_data { + stdin_data.clone() + } else if let Some(path) = &args.file { + fs::read(&path).await? + } else { + // No path input, exit early + return early_cmd_output!(JVNoneOutput => JVNoneOutput); + }; Ok(Collect { data }) } |
