summaryrefslogtreecommitdiff
path: root/src/cmds
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmds')
-rw-r--r--src/cmds/arg/storage_build.rs12
-rw-r--r--src/cmds/arg/storage_write.rs33
-rw-r--r--src/cmds/cmd/sheetedit.rs10
-rw-r--r--src/cmds/cmd/storage_build.rs70
-rw-r--r--src/cmds/cmd/storage_write.rs110
-rw-r--r--src/cmds/in/storage_rw.rs11
-rw-r--r--src/cmds/renderer/mappings_pretty.rs8
7 files changed, 10 insertions, 244 deletions
diff --git a/src/cmds/arg/storage_build.rs b/src/cmds/arg/storage_build.rs
deleted file mode 100644
index 5d57b97..0000000
--- a/src/cmds/arg/storage_build.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-use std::path::PathBuf;
-
-use clap::Parser;
-
-#[derive(Parser, Debug)]
-pub struct JVStorageBuildArgument {
- pub index_file: PathBuf,
- pub storage: PathBuf,
-
- #[arg(short = 'o', long = "output")]
- pub output_file: Option<PathBuf>,
-}
diff --git a/src/cmds/arg/storage_write.rs b/src/cmds/arg/storage_write.rs
deleted file mode 100644
index e00dfdf..0000000
--- a/src/cmds/arg/storage_write.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-use std::path::PathBuf;
-
-use clap::Parser;
-
-#[derive(Parser, Debug)]
-pub struct JVStorageWriteArgument {
- pub file: PathBuf,
- pub storage: PathBuf,
-
- #[arg(short = 'o', long = "output")]
- pub output_index: Option<PathBuf>,
-
- #[arg(long = "line")]
- pub line_chunking: bool,
-
- #[arg(long = "cdc", default_value_t = 0)]
- pub cdc_chunking: u32,
-
- #[arg(long = "fixed", default_value_t = 0)]
- pub fixed_chunking: u32,
-
- #[arg(long)]
- pub b: bool,
-
- #[arg(long)]
- pub kb: bool, // default chunk size unit
-
- #[arg(long)]
- pub mb: bool,
-
- #[arg(long)]
- pub gb: bool,
-}
diff --git a/src/cmds/cmd/sheetedit.rs b/src/cmds/cmd/sheetedit.rs
index 3e61642..74b0bbe 100644
--- a/src/cmds/cmd/sheetedit.rs
+++ b/src/cmds/cmd/sheetedit.rs
@@ -10,7 +10,9 @@ use crate::{
},
};
use cli_utils::{
- display::SimpleTable, env::get_default_editor, input::input_with_editor_cutsom, string_vec,
+ display::table::Table,
+ legacy::{env::get_default_editor, input::input_with_editor_cutsom},
+ string_vec,
};
use cmd_system_macros::exec;
use just_enough_vcs::system::sheet_system::{mapping::LocalMapping, sheet::SheetData};
@@ -96,7 +98,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String {
t!("sheetedit.forward")
];
- let mut simple_table = SimpleTable::new(header);
+ let mut table = Table::new(header);
for mapping in mappings {
let mapping_str = mapping
@@ -105,7 +107,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String {
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<String>>();
- simple_table.push_item(vec![
+ table.push_item(vec![
format!(
" {} ",
mapping_str.get(0).unwrap_or(&String::default())
@@ -116,7 +118,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String {
format!("{} ", mapping_str.get(4).unwrap_or(&String::default())), // Forward
]);
}
- simple_table.to_string()
+ table.to_string()
}
crate::command_template!();
diff --git a/src/cmds/cmd/storage_build.rs b/src/cmds/cmd/storage_build.rs
deleted file mode 100644
index 8e4d39c..0000000
--- a/src/cmds/cmd/storage_build.rs
+++ /dev/null
@@ -1,70 +0,0 @@
-use crate::{
- cmd_output,
- cmds::{
- arg::storage_build::JVStorageBuildArgument, collect::empty::JVEmptyCollect,
- r#in::storage_rw::JVStorageRWInput, out::none::JVNoneOutput,
- },
- systems::cmd::{
- cmd_system::JVCommandContext,
- errors::{CmdExecuteError, CmdPrepareError},
- },
-};
-use cli_utils::display::md;
-use cmd_system_macros::exec;
-use just_enough_vcs::system::storage_system::{error::StorageIOError, store::build_file};
-use rust_i18n::t;
-use std::any::TypeId;
-
-pub struct JVStorageBuildCommand;
-type Cmd = JVStorageBuildCommand;
-type Arg = JVStorageBuildArgument;
-type In = JVStorageRWInput;
-type Collect = JVEmptyCollect;
-
-fn help_str() -> String {
- todo!()
-}
-
-async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
- let output_file = match &args.output_file {
- Some(v) => v.clone(),
- None => args.index_file.clone().with_extension("unknown"),
- };
-
- let (input, storage, output) = just_enough_vcs::system::storage_system::store::precheck(
- args.index_file.clone(),
- args.storage.clone(),
- output_file,
- )
- .await?;
-
- Ok(JVStorageRWInput {
- input,
- storage,
- output,
- chunking_policy: None,
- })
-}
-
-async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {
- Ok(Collect {})
-}
-
-#[exec]
-async fn exec(
- input: In,
- _collect: Collect,
-) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> {
- build_file(input.input, input.storage, input.output)
- .await
- .map_err(|e| match e {
- StorageIOError::IOErr(error) => CmdExecuteError::Io(error),
- StorageIOError::HashTooShort => {
- CmdExecuteError::Error(md(t!("storage_write.hash_too_short")).to_string())
- }
- })?;
-
- cmd_output!(JVNoneOutput => JVNoneOutput {})
-}
-
-crate::command_template!();
diff --git a/src/cmds/cmd/storage_write.rs b/src/cmds/cmd/storage_write.rs
deleted file mode 100644
index 8c864a8..0000000
--- a/src/cmds/cmd/storage_write.rs
+++ /dev/null
@@ -1,110 +0,0 @@
-use crate::{
- cmd_output,
- cmds::{
- arg::storage_write::JVStorageWriteArgument, collect::empty::JVEmptyCollect,
- r#in::storage_rw::JVStorageRWInput, out::none::JVNoneOutput,
- },
- systems::cmd::{
- cmd_system::JVCommandContext,
- errors::{CmdExecuteError, CmdPrepareError},
- },
-};
-use cli_utils::display::md;
-use cmd_system_macros::exec;
-use just_enough_vcs::system::{
- constants::vault::values::vault_value_index_file_suffix,
- storage_system::{
- error::StorageIOError,
- store::{ChunkingPolicy, StorageConfig, write_file},
- },
-};
-use rust_i18n::t;
-use std::any::TypeId;
-
-pub struct JVStorageWriteCommand;
-type Cmd = JVStorageWriteCommand;
-type Arg = JVStorageWriteArgument;
-type In = JVStorageRWInput;
-type Collect = JVEmptyCollect;
-
-fn help_str() -> String {
- todo!()
-}
-
-async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> {
- let output_path = match &args.output_index {
- Some(v) => v.clone(),
- None => args
- .file
- .clone()
- .with_extension(vault_value_index_file_suffix()),
- };
-
- // Default to using kb as the unit
- let scale = if args.gb {
- 1024 * 1024 * 1024
- } else if args.mb {
- 1024 * 1024
- } else if args.b {
- 1
- } else {
- 1024
- };
-
- let (input, storage, output) = just_enough_vcs::system::storage_system::store::precheck(
- args.file.clone(),
- args.storage.clone(),
- output_path,
- )
- .await?;
-
- let chunking_policy: ChunkingPolicy = if args.cdc_chunking > 0 {
- ChunkingPolicy::Cdc(args.cdc_chunking * scale)
- } else if args.fixed_chunking > 0 {
- ChunkingPolicy::FixedSize(args.fixed_chunking * scale)
- } else if args.line_chunking {
- ChunkingPolicy::Line
- } else {
- return Err(CmdPrepareError::Error(md(t!(
- "storage_write.unknown_chunking_policy"
- ))));
- };
-
- Ok(JVStorageRWInput {
- input,
- storage,
- output,
- chunking_policy: Some(chunking_policy),
- })
-}
-
-async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> {
- Ok(JVEmptyCollect {})
-}
-
-#[exec]
-async fn exec(
- input: In,
- _collect: Collect,
-) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> {
- // There is no chance to return None in the Prepare phase, so unwrap is safe here
- let chunking_policy = input.chunking_policy.unwrap();
-
- write_file(
- input.input,
- input.storage,
- input.output,
- &StorageConfig { chunking_policy },
- )
- .await
- .map_err(|e| match e {
- StorageIOError::IOErr(error) => CmdExecuteError::Io(error),
- StorageIOError::HashTooShort => {
- CmdExecuteError::Error(md(t!("storage_write.hash_too_short")).to_string())
- }
- })?;
-
- cmd_output!(JVNoneOutput => JVNoneOutput {})
-}
-
-crate::command_template!();
diff --git a/src/cmds/in/storage_rw.rs b/src/cmds/in/storage_rw.rs
deleted file mode 100644
index 596c1f9..0000000
--- a/src/cmds/in/storage_rw.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-use std::path::PathBuf;
-
-use just_enough_vcs::system::storage_system::store::ChunkingPolicy;
-
-pub struct JVStorageRWInput {
- pub input: PathBuf,
- pub storage: PathBuf,
- pub output: PathBuf,
-
- pub chunking_policy: Option<ChunkingPolicy>,
-}
diff --git a/src/cmds/renderer/mappings_pretty.rs b/src/cmds/renderer/mappings_pretty.rs
index dad4d95..6431302 100644
--- a/src/cmds/renderer/mappings_pretty.rs
+++ b/src/cmds/renderer/mappings_pretty.rs
@@ -1,4 +1,4 @@
-use cli_utils::{display::SimpleTable, string_vec};
+use cli_utils::{display::table::Table, string_vec};
use colored::Colorize;
use just_enough_vcs::system::sheet_system::mapping::LocalMapping;
use render_system_macros::result_renderer;
@@ -29,7 +29,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String {
"|"
];
- let mut simple_table = SimpleTable::new(header);
+ let mut table = Table::new(header);
let mut i = 1;
for mapping in mappings {
@@ -39,7 +39,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String {
.into_iter()
.map(|s| s.to_string())
.collect::<Vec<String>>();
- simple_table.push_item(vec![
+ table.push_item(vec![
// Number
format!("{}", i).bold().to_string(),
// Mapping
@@ -89,5 +89,5 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String {
i += 1;
}
- simple_table.to_string()
+ table.to_string()
}