Skip to content

Commit

Permalink
Merge pull request #1044 from leviathanbeak/leviathanbeak/migrate_to_…
Browse files Browse the repository at this point in the history
…clap_from_next

refactor: switch to clap
  • Loading branch information
bobbinth authored Aug 16, 2023
2 parents 0b04783 + 51ec1f6 commit f67b722
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 77 deletions.
4 changes: 2 additions & 2 deletions miden/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ path = "tests/integration/main.rs"
[features]
concurrent = ["prover/concurrent", "std"]
default = ["std"]
executable = ["env_logger", "hex/std", "std", "serde/std", "serde_derive", "serde_json/std", "structopt", "rustyline"]
executable = ["env_logger", "hex/std", "std", "serde/std", "serde_derive", "serde_json/std", "clap", "rustyline"]
std = ["assembly/std", "log/std", "processor/std", "prover/std", "verifier/std"]

[dependencies]
assembly = { package = "miden-assembly", path = "../assembly", version = "0.7", default-features = false }
clap = { version = "3.0", features = ["derive"], optional = true }
env_logger = { version = "0.10", default-features = false, optional = true }
hex = { version = "0.4", optional = true }
log = { version = "0.4", default-features = false }
Expand All @@ -54,7 +55,6 @@ serde = {version = "1.0.117", optional = true }
serde_derive = {version = "1.0.117", optional = true }
serde_json = {version = "1.0.59", optional = true }
stdlib = { package = "miden-stdlib", path = "../stdlib", version = "0.6", default-features = false }
structopt = { version = "0.3", default-features = false, optional = true }
verifier = { package = "miden-verifier", path = "../verifier", version = "0.7", default-features = false }

[dev-dependencies]
Expand Down
12 changes: 6 additions & 6 deletions miden/src/cli/bundle.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use assembly::{LibraryNamespace, MaslLibrary, Version};
use clap::Parser;
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(
#[derive(Debug, Clone, Parser)]
#[clap(
name = "Compile Library",
about = "Bundles .masm files into a single .masl library"
)]
pub struct BundleCmd {
/// Path to a directory containing the `.masm` files which are part of the library.
#[structopt(parse(from_os_str))]
#[clap(value_parser)]
dir: PathBuf,
/// Defines the top-level namespace, e.g. `mylib`, otherwise the directory name is used.
#[structopt(short, long)]
#[clap(short, long)]
namespace: Option<String>,
/// Version of the library, defaults to `0.1.0`.
#[structopt(short, long, default_value = "0.1.0")]
#[clap(short, long, default_value = "0.1.0")]
version: String,
}

Expand Down
11 changes: 6 additions & 5 deletions miden/src/cli/compile.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use clap::Parser;

use super::data::{Debug, Libraries, ProgramFile};
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "Compile", about = "Compile a miden program")]
#[derive(Debug, Clone, Parser)]
#[clap(about = "Compile a miden program")]
pub struct CompileCmd {
/// Path to .masm assembly file
#[structopt(short = "a", long = "assembly", parse(from_os_str))]
#[clap(short = 'a', long = "assembly", value_parser)]
assembly_file: PathBuf,
/// Paths to .masl library files
#[structopt(short = "l", long = "libraries", parse(from_os_str))]
#[clap(short = 'l', long = "libraries", value_parser)]
library_paths: Vec<PathBuf>,
}

Expand Down
14 changes: 7 additions & 7 deletions miden/src/cli/debug/mod.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use super::data::{Debug, InputFile, Libraries, ProgramFile};
use clap::Parser;
use rustyline::{error::ReadlineError, Config, DefaultEditor, EditMode};
use std::path::PathBuf;
use structopt::StructOpt;

mod command;
use command::DebugCommand;

mod executor;
use executor::DebugExecutor;

#[derive(StructOpt, Debug)]
#[structopt(name = "Debug", about = "Debug a miden program")]
#[derive(Debug, Clone, Parser)]
#[clap(about = "Debug a miden program")]
pub struct DebugCmd {
/// Path to .masm assembly file
#[structopt(short = "a", long = "assembly", parse(from_os_str))]
#[clap(short = 'a', long = "assembly", value_parser)]
assembly_file: PathBuf,
/// Path to input file
#[structopt(short = "i", long = "input", parse(from_os_str))]
#[clap(short = 'i', long = "input", value_parser)]
input_file: Option<PathBuf>,
/// Enable vi edit mode
#[structopt(short = "vi", long = "vim_edit_mode")]
#[clap(long = "vi", long = "vim_edit_mode")]
vim_edit_mode: Option<String>,
/// Paths to .masl library files
#[structopt(short = "l", long = "libraries", parse(from_os_str))]
#[clap(short = 'l', long = "libraries", value_parser)]
library_paths: Vec<PathBuf>,
}

Expand Down
28 changes: 14 additions & 14 deletions miden/src/cli/prove.rs
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
use super::data::{Debug, InputFile, Libraries, OutputFile, ProgramFile, ProofFile};
use clap::Parser;
use miden::ProvingOptions;
use processor::{ExecutionOptions, ExecutionOptionsError};
use std::{io::Write, path::PathBuf, time::Instant};
use structopt::StructOpt;

// TODO check if structopt is supporting automatic generation of list values of hash function
#[derive(StructOpt, Debug)]
#[structopt(name = "Prove", about = "Prove a miden program")]
// TODO check if clap is supporting automatic generation of list values of hash function
#[derive(Debug, Clone, Parser)]
#[clap(about = "Prove a miden program")]
pub struct ProveCmd {
/// Path to .masm assembly file
#[structopt(short = "a", long = "assembly", parse(from_os_str))]
#[clap(short = 'a', long = "assembly", value_parser)]
assembly_file: PathBuf,

/// Number of cycles the program is expected to consume
#[structopt(short = "e", long = "exp-cycles", default_value = "64")]
#[clap(short = 'e', long = "exp-cycles", default_value = "64")]
expected_cycles: u32,

/// Path to input file
#[structopt(short = "i", long = "input", parse(from_os_str))]
#[clap(short = 'i', long = "input", value_parser)]
input_file: Option<PathBuf>,

/// Paths to .masl library files
#[structopt(short = "l", long = "libraries", parse(from_os_str))]
#[clap(short = 'l', long = "libraries", value_parser)]
library_paths: Vec<PathBuf>,

/// Maximum number of cycles a program is allowed to consume
#[structopt(short = "m", long = "max-cycles", default_value = "4294967295")]
#[clap(short = 'm', long = "max-cycles", default_value = "4294967295")]
max_cycles: u32,

/// Number of outputs
#[structopt(short = "n", long = "num-outputs", default_value = "16")]
#[clap(short = 'n', long = "num-outputs", default_value = "16")]
num_outputs: usize,

/// Path to output file
#[structopt(short = "o", long = "output", parse(from_os_str))]
#[clap(short = 'o', long = "output", value_parser)]
output_file: Option<PathBuf>,

/// Path to proof file
#[structopt(short = "p", long = "proof", parse(from_os_str))]
#[clap(short = 'p', long = "proof", value_parser)]
proof_file: Option<PathBuf>,

/// Enable generation of proofs suitable for recursive verification
#[structopt(short = "r", long = "recursive")]
#[clap(short = 'r', long = "recursive")]
recursive: bool,

/// Security level for execution proofs generated by the VM
#[structopt(short = "s", long = "security", default_value = "96bits")]
#[clap(short = 's', long = "security", default_value = "96bits")]
security: String,
}

Expand Down
7 changes: 4 additions & 3 deletions miden/src/cli/repl.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use clap::Parser;

use crate::repl::start_repl;
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "Repl", about = "Initiates the Miden REPL tool")]
#[derive(Debug, Clone, Parser)]
#[clap(about = "Initiates the Miden REPL tool")]
pub struct ReplCmd {}

impl ReplCmd {
Expand Down
20 changes: 10 additions & 10 deletions miden/src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
use super::data::{Debug, InputFile, Libraries, OutputFile, ProgramFile};
use clap::Parser;
use processor::ExecutionOptions;
use std::{path::PathBuf, time::Instant};
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "Run", about = "Run a miden program")]
#[derive(Debug, Clone, Parser)]
#[clap(about = "Run a miden program")]
pub struct RunCmd {
/// Path to .masm assembly file
#[structopt(short = "a", long = "assembly", parse(from_os_str))]
#[clap(short = 'a', long = "assembly", value_parser)]
assembly_file: PathBuf,

/// Number of cycles the program is expected to consume
#[structopt(short = "e", long = "exp-cycles", default_value = "64")]
#[clap(short = 'e', long = "exp-cycles", default_value = "64")]
expected_cycles: u32,

/// Path to input file
#[structopt(short = "i", long = "input", parse(from_os_str))]
#[clap(short = 'i', long = "input", value_parser)]
input_file: Option<PathBuf>,

/// Paths to .masl library files
#[structopt(short = "l", long = "libraries", parse(from_os_str))]
#[clap(short = 'l', long = "libraries", value_parser)]
library_paths: Vec<PathBuf>,

/// Maximum number of cycles a program is allowed to consume
#[structopt(short = "m", long = "max-cycles", default_value = "4294967295")]
#[clap(short = 'm', long = "max-cycles", default_value = "4294967295")]
max_cycles: u32,

/// Number of ouptuts
#[structopt(short = "n", long = "num-outputs", default_value = "16")]
#[clap(short = 'n', long = "num-outputs", default_value = "16")]
num_outputs: usize,

/// Path to output file
#[structopt(short = "o", long = "output", parse(from_os_str))]
#[clap(short = 'o', long = "output", value_parser)]
output_file: Option<PathBuf>,
}

Expand Down
14 changes: 7 additions & 7 deletions miden/src/cli/verify.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use super::data::{InputFile, OutputFile, ProgramHash, ProofFile};
use clap::Parser;
use miden::{Kernel, ProgramInfo};
use std::{path::PathBuf, time::Instant};
use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(name = "Verify", about = "Verify a miden program")]
#[derive(Debug, Clone, Parser)]
#[clap(about = "Verify a miden program")]
pub struct VerifyCmd {
/// Path to input file
#[structopt(short = "i", long = "input", parse(from_os_str))]
#[clap(short = 'i', long = "input", value_parser)]
input_file: Option<PathBuf>,
/// Path to output file
#[structopt(short = "o", long = "output", parse(from_os_str))]
#[clap(short = 'o', long = "output", value_parser)]
output_file: Option<PathBuf>,
/// Path to proof file
#[structopt(short = "p", long = "proof", parse(from_os_str))]
#[clap(short = 'p', long = "proof", value_parser)]
proof_file: PathBuf,
/// Program hash (hex)
#[structopt(short = "h", long = "program-hash")]
#[clap(short = 'h', long = "program-hash")]
program_hash: String,
}

Expand Down
24 changes: 12 additions & 12 deletions miden/src/examples/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use clap::Parser;
use miden::{AdviceProvider, ExecutionProof, Program, ProgramInfo, ProvingOptions, StackInputs};
use processor::{ExecutionOptions, ExecutionOptionsError};
use std::io::Write;
use std::time::Instant;
use structopt::StructOpt;

pub mod fibonacci;

Expand All @@ -23,36 +23,36 @@ where
// EXAMPLE OPTIONS
// ================================================================================================

#[derive(StructOpt, Debug)]
#[structopt(name = "Examples", about = "Run an example miden program")]
#[derive(Debug, Clone, Parser)]
#[clap(about = "Run an example miden program")]
pub struct ExampleOptions {
#[structopt(subcommand)]
#[clap(subcommand)]
pub example: ExampleType,

/// Number of cycles the program is expected to consume
#[structopt(short = "e", long = "exp-cycles", default_value = "64")]
#[clap(short = 'r', long = "exp-cycles", default_value = "64")]
expected_cycles: u32,

/// Maximum number of cycles a program is allowed to consume
#[structopt(short = "m", long = "max-cycles", default_value = "4294967295")]
#[clap(short = 'm', long = "max-cycles", default_value = "4294967295")]
max_cycles: u32,

/// Enable generation of proofs suitable for recursive verification
#[structopt(short = "r", long = "recursive")]
#[clap(short = 'r', long = "recursive")]
recursive: bool,

/// Security level for execution proofs generated by the VM
#[structopt(short = "s", long = "security", default_value = "96bits")]
/// Security level for execution proofs generated by the VM
#[clap(short = 's', long = "security", default_value = "96bits")]
security: String,
}

#[derive(StructOpt, Debug)]
//#[structopt(about = "available examples")]
#[derive(Debug, Clone, Parser)]
//#[clap(about = "available examples")]
pub enum ExampleType {
/// Compute a Fibonacci sequence of the specified length
Fib {
/// Length of Fibonacci sequence
#[structopt(short = "n", default_value = "1024")]
#[clap(short = 'n', default_value = "1024")]
sequence_length: usize,
},
}
Expand Down
12 changes: 6 additions & 6 deletions miden/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use clap::Parser;
use core::fmt;
use miden::{AssemblyError, ExecutionError};
use structopt::StructOpt;

mod cli;
mod examples;
mod repl;
mod tools;

/// Root CLI struct
#[derive(StructOpt, Debug)]
#[structopt(name = "Miden", about = "Miden CLI")]
#[derive(Parser, Debug)]
#[clap(name = "Miden", about = "Miden CLI", version, rename_all = "kebab-case")]
pub struct Cli {
#[structopt(subcommand)]
#[clap(subcommand)]
action: Actions,
}

/// CLI actions
#[derive(StructOpt, Debug)]
#[derive(Debug, Parser)]
pub enum Actions {
Analyze(tools::Analyze),
Compile(cli::CompileCmd),
Expand Down Expand Up @@ -51,7 +51,7 @@ impl Cli {
/// Executable entry point
pub fn main() {
// read command-line args
let cli = Cli::from_args();
let cli = Cli::parse();

// execute cli action
if let Err(error) = cli.execute() {
Expand Down
10 changes: 5 additions & 5 deletions miden/src/tools/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
use super::{cli::InputFile, ProgramError};
use clap::Parser;
use core::fmt;
use miden::{utils::collections::Vec, AdviceProvider, Assembler, Operation, StackInputs};
use processor::AsmOpInfo;
use std::{fs, path::PathBuf};
use stdlib::StdLibrary;
use structopt::StructOpt;

// CLI
// ================================================================================================

/// Defines cli interface
#[derive(StructOpt, Debug)]
#[structopt(about = "Analyze a miden program")]
#[derive(Debug, Clone, Parser)]
#[clap(about = "Analyze a miden program")]
pub struct Analyze {
/// Path to .masm assembly file
#[structopt(short = "a", long = "assembly", parse(from_os_str))]
#[clap(short = 'a', long = "assembly", value_parser)]
assembly_file: PathBuf,
/// Path to .inputs file
#[structopt(short = "i", long = "input", parse(from_os_str))]
#[clap(short = 'i', long = "input", value_parser)]
input_file: Option<PathBuf>,
}

Expand Down

0 comments on commit f67b722

Please sign in to comment.