Skip to content

Aiken branch: improve argument parsing for the examples and the aiken-transactions-middleware #31

@NicolasDP

Description

@NicolasDP

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,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions