Currently we parse the environment variables and CLI arguments by hand. We also generate the CLI help message by hand too.
We can do more with less code using clap.
For example something like
|
let args: Vec<String> = env::args().collect(); |
|
|
|
match &args[1..] { |
|
[] => { |
|
compile_atms_circuit::<KZGCommitmentScheme<Bls12>>(); |
|
} |
|
[command] if command == "gwc_kzg" => { |
|
compile_atms_circuit::<GwcKZGCommitmentScheme<Bls12>>(); |
|
} |
|
_ => { |
|
println!("Usage:"); |
|
println!("- to run the example: `cargo run --example example_name`"); |
|
println!( |
|
"- to run the example using the GWC19 version of multi-open KZG, run: `cargo run --example example_name gwc_kzg`" |
|
); |
|
} |
|
} |
could easily become something along the line of:
#[derive(clap::Parser)]
struct Command {
#[subcommand]
command: Choice,
}
#[derive(clap::Command, Default)]
enum Choice {
#[default]
KZG,
/// run the example using the GWC19 version of multi-open KZG
GWC,
}
let Command { choice } = Command::parse();
The necessary environment variable could also be extracted using clap:
struct Command {
/// set the Blockfrost API KEY
#[parse(env = "BLOCK_FROST_API_KEY")]
api_key: String,
}
Currently we parse the environment variables and CLI arguments by hand. We also generate the CLI help message by hand too.
We can do more with less code using
clap.For example something like
plutus-halo2-verifier-gen/examples/atms.rs
Lines 28 to 44 in dd9d0e2
could easily become something along the line of:
The necessary environment variable could also be extracted using
clap: