summaryrefslogtreecommitdiff
path: root/src/cmds/cmd
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-02-25 10:58:51 +0800
committer魏曹先生 <1992414357@qq.com>2026-02-25 10:58:51 +0800
commitec6fdf88419a7fdad0128f04bb7a0478776974ab (patch)
tree1e44067a7afef878bed9b8b228f6555806e77738 /src/cmds/cmd
parent6bd344793e5c2e84361475d6e221007ef21faaad (diff)
Add hexdump and sheetdump commands
Diffstat (limited to 'src/cmds/cmd')
-rw-r--r--src/cmds/cmd/hexdump.rs44
-rw-r--r--src/cmds/cmd/sheetdump.rs62
-rw-r--r--src/cmds/cmd/status.rs6
3 files changed, 109 insertions, 3 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!();
diff --git a/src/cmds/cmd/sheetdump.rs b/src/cmds/cmd/sheetdump.rs
new file mode 100644
index 0000000..3b0953a
--- /dev/null
+++ b/src/cmds/cmd/sheetdump.rs
@@ -0,0 +1,62 @@
+use crate::{
+ cmd_output,
+ cmds::{
+ arg::sheetdump::JVSheetdumpArgument, collect::sheetdump::JVSheetdumpCollect,
+ r#in::sheetdump::JVSheetdumpInput, out::mappings::JVMappingsOutput,
+ },
+ systems::cmd::{
+ cmd_system::JVCommandContext,
+ errors::{CmdExecuteError, CmdPrepareError},
+ },
+};
+use cmd_system_macros::exec;
+use just_enough_vcs::system::sheet_system::{
+ mapping::LocalMapping,
+ sheet::{SheetData, error::ReadSheetDataError},
+};
+
+pub struct JVSheetdumpCommand;
+type Cmd = JVSheetdumpCommand;
+type Arg = JVSheetdumpArgument;
+type In = JVSheetdumpInput;
+type Collect = JVSheetdumpCollect;
+
+fn help_str() -> String {
+ todo!()
+}
+
+async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
+ Ok(In { sort: args.sort })
+}
+
+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),
+ })?;
+
+ Ok(Collect { sheet: sheet })
+}
+
+#[exec]
+async fn exec(
+ input: In,
+ collect: Collect,
+) -> Result<(Box<dyn std::any::Any + Send + 'static>, String), CmdExecuteError> {
+ let mappings = collect.sheet.mappings();
+ let mut mappings_vec = mappings.iter().cloned().collect::<Vec<LocalMapping>>();
+ if input.sort {
+ mappings_vec.sort();
+ }
+
+ let result = JVMappingsOutput {
+ mappings: mappings_vec,
+ };
+ cmd_output!(result, JVMappingsOutput)
+}
+
+crate::command_template!();
diff --git a/src/cmds/cmd/status.rs b/src/cmds/cmd/status.rs
index 4e89d42..c1f2a96 100644
--- a/src/cmds/cmd/status.rs
+++ b/src/cmds/cmd/status.rs
@@ -5,7 +5,7 @@ use crate::{
cmds::{
arg::status::JVStatusArgument,
collect::status::JVStatusCollect,
- r#in::status::JVStatusInput,
+ r#in::empty::JVEmptyInput,
out::status::{JVStatusOutput, JVStatusWrongModifyReason},
},
systems::cmd::{
@@ -22,7 +22,7 @@ use just_enough_vcs::lib::{
pub struct JVStatusCommand;
type Cmd = JVStatusCommand;
type Arg = JVStatusArgument;
-type In = JVStatusInput;
+type In = JVEmptyInput;
type Collect = JVStatusCollect;
fn help_str() -> String {
@@ -30,7 +30,7 @@ fn help_str() -> String {
}
async fn prepare(_args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
- Ok(JVStatusInput)
+ Ok(In {})
}
async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {