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
This commit is contained in:
tyshko-rostyslav 2023-05-29 15:19:18 +02:00 committed by GitHub
parent 2c4de0484a
commit 3177e3ae74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 4 deletions

View File

@ -33,4 +33,12 @@ pub(crate) enum Commands {
#[arg(short, long)]
file: PathBuf,
},
SetNextLeaf {
#[arg(short, long)]
file: PathBuf,
},
DeleteLeaf {
index: usize,
},
GetRoot,
}

View File

@ -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(()),
}
}