Skip to content

Commit

Permalink
feat(cli): ✨ Add command all to run all the other commands end-2-end
Browse files Browse the repository at this point in the history
  • Loading branch information
SpiralOutDotEu committed Nov 2, 2023
1 parent 7f843a3 commit 25c0886
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use clap::{Parser, Subcommand};
use fake::{faker::lorem::en::Sentence, Fake};
use std::io;
mod commands;
use self::commands::{movejs, proofs};
use crate::utils::{command_runner::RealCommandRunner, filesystem_operations::RealFileSystemOps};
use commands::{circuit, compile, setup, verifier};
use commands::{all, circuit, compile, movejs, proofs, setup, verifier};

/// Represents the command line interface for the Zero Knowledge Whitelist Tool.
/// Deriving `Parser` from clap allows for automatic parsing of command line arguments.
Expand Down Expand Up @@ -37,6 +36,8 @@ pub enum SubCommand {
Movejs,
/// Generates proofs using an input file, with a default value of "addresses.txt".
Proofs(ProofsCommand),
/// Run all the commands one after the other, {circuit, compile, setup, verifier, movejs, proofs} using an input file, with a default value of "addresses.txt"
All(AllCommand),
}

#[derive(Parser, PartialEq, Debug)]
Expand All @@ -45,6 +46,12 @@ pub struct ProofsCommand {
pub input_file: String,
}

#[derive(Parser, PartialEq, Debug)]
pub struct AllCommand {
#[clap(long, default_value = "addresses.txt")]
pub input_file: String,
}

/// The entry point of the application.
/// Parses command line arguments and executes the corresponding subcommand.
pub fn run_cli() -> std::io::Result<()> {
Expand All @@ -64,6 +71,15 @@ pub fn run_cli() -> std::io::Result<()> {
proofs::handle_proofs_subcommand(&runner, &proofs_command.input_file, &file_system_ops)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?
}
SubCommand::All(all_command) => {
all::handle_all_command(
runner,
random_name,
random_text,
file_system_ops,
all_command,
)?;
}
};

Ok(())
Expand Down Expand Up @@ -124,4 +140,26 @@ mod tests {
})
);
}

#[test]
fn test_parse_all_subcommand_with_default_value() {
let args = Cli::parse_from(&["zk_whitelist", "all"]);
assert_eq!(
args.subcmd,
SubCommand::All(AllCommand {
input_file: "addresses.txt".to_string()
})
);
}

#[test]
fn test_parse_all_subcommand_with_custom_value() {
let args = Cli::parse_from(&["zk_whitelist", "all", "--input-file", "custom.txt"]);
assert_eq!(
args.subcmd,
SubCommand::All(AllCommand {
input_file: "custom.txt".to_string()
})
);
}
}
15 changes: 15 additions & 0 deletions src/cli/commands/all.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use crate::{utils::{command_runner::RealCommandRunner, filesystem_operations::RealFileSystemOps}, cli::AllCommand};
use std::io;

use super::{circuit, compile, setup, verifier, movejs, proofs};

pub fn handle_all_command(runner: RealCommandRunner, random_name: String, random_text: String, file_system_ops: RealFileSystemOps, all_command: AllCommand) -> Result<(), io::Error> {
circuit::handle_circuit_subcommand()?;
compile::handle_compile_subcommand(&runner)?;
setup::handle_setup_subcommand(&runner, random_name.clone(), random_text.clone())?;
verifier::handle_verifier_subcommand(&runner)?;
movejs::handle_movejs_subcommand(&file_system_ops)?;
proofs::handle_proofs_subcommand(&runner, &all_command.input_file, &file_system_ops)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
Ok(())
}
1 change: 1 addition & 0 deletions src/cli/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod movejs;
pub mod proofs;
pub mod setup;
pub mod verifier;
pub mod all;

0 comments on commit 25c0886

Please sign in to comment.