From 3177e3ae74dc006a74c920bedebfd9fe2853e61e Mon Sep 17 00:00:00 2001 From: tyshko-rostyslav <122977916+tyshko-rostyslav@users.noreply.github.com> Date: Mon, 29 May 2023 15:19:18 +0200 Subject: [PATCH] MVP CLI Proposal implementation: leaf and root interactions (#167) * next feaf command * delete leaf command * get root command * next feaf call * delete leaf call * get root call * better error comment * to stdout * fmt --- rln-cli/src/commands.rs | 8 ++++++++ rln-cli/src/main.rs | 31 +++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/rln-cli/src/commands.rs b/rln-cli/src/commands.rs index b43051a..dbc9f16 100644 --- a/rln-cli/src/commands.rs +++ b/rln-cli/src/commands.rs @@ -33,4 +33,12 @@ pub(crate) enum Commands { #[arg(short, long)] file: PathBuf, }, + SetNextLeaf { + #[arg(short, long)] + file: PathBuf, + }, + DeleteLeaf { + index: usize, + }, + GetRoot, } diff --git a/rln-cli/src/main.rs b/rln-cli/src/main.rs index efc6878..a704118 100644 --- a/rln-cli/src/main.rs +++ b/rln-cli/src/main.rs @@ -54,7 +54,7 @@ fn main() -> Result<()> { Some(Commands::SetTree { tree_height }) => { state .rln - .ok_or(Report::msg("no RLN initialized"))? + .ok_or(Report::msg("no RLN instance initialized"))? .set_tree(*tree_height)?; Ok(()) } @@ -62,7 +62,7 @@ fn main() -> Result<()> { let input_data = File::open(&file)?; state .rln - .ok_or(Report::msg("no RLN initialized"))? + .ok_or(Report::msg("no RLN instance initialized"))? .set_leaf(*index, input_data)?; Ok(()) } @@ -70,7 +70,7 @@ fn main() -> Result<()> { let input_data = File::open(&file)?; state .rln - .ok_or(Report::msg("no RLN initialized"))? + .ok_or(Report::msg("no RLN instance initialized"))? .set_leaves_from(*index, input_data)?; Ok(()) } @@ -78,10 +78,33 @@ fn main() -> Result<()> { let input_data = File::open(&file)?; state .rln - .ok_or(Report::msg("no RLN initialized"))? + .ok_or(Report::msg("no RLN instance initialized"))? .init_tree_with_leaves(input_data)?; Ok(()) } + Some(Commands::SetNextLeaf { file }) => { + let input_data = File::open(&file)?; + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .set_next_leaf(input_data)?; + Ok(()) + } + Some(Commands::DeleteLeaf { index }) => { + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .delete_leaf(*index)?; + Ok(()) + } + Some(Commands::GetRoot) => { + let writer = std::io::stdout(); + state + .rln + .ok_or(Report::msg("no RLN instance initialized"))? + .get_root(writer)?; + Ok(()) + } None => Ok(()), } }