diff options
Diffstat (limited to 'src/cmds/cmd/hexdump.rs')
| -rw-r--r-- | src/cmds/cmd/hexdump.rs | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/cmds/cmd/hexdump.rs b/src/cmds/cmd/hexdump.rs new file mode 100644 index 0000000..a0f4a21 --- /dev/null +++ b/src/cmds/cmd/hexdump.rs @@ -0,0 +1,44 @@ +use crate::{ + cmd_output, + cmds::{ + arg::single_file::JVSingleFileArgument, collect::single_file::JVSingleFileCollect, + r#in::empty::JVEmptyInput, out::hex::JVHexOutput, + }, + systems::cmd::{ + cmd_system::JVCommandContext, + errors::{CmdExecuteError, CmdPrepareError}, + }, +}; +use cmd_system_macros::exec; +use tokio::fs; + +pub struct JVHexdumpCommand; +type Cmd = JVHexdumpCommand; +type Arg = JVSingleFileArgument; +type In = JVEmptyInput; +type Collect = JVSingleFileCollect; + +fn help_str() -> String { + "Hello".to_string() +} + +async fn prepare(_args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> { + Ok(In {}) +} + +async fn collect(args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> { + let file = &args.file; + let data = fs::read(file).await?; + Ok(Collect { data }) +} + +#[exec] +async fn exec( + _input: In, + collect: Collect, +) -> Result<(Box<dyn std::any::Any + Send + 'static>, String), CmdExecuteError> { + let output = JVHexOutput { data: collect.data }; + cmd_output!(output, JVHexOutput) +} + +crate::command_template!(); |
