Macro clap_command

Source
macro_rules! clap_command {
    ($state: ty, $clap: ty, async $inc: expr) => { ... };
    ($state: ty, $clap: ty, $inc: expr) => { ... };
}
Available on crate feature clap only.
Expand description

Creates a Command which takes a clap::Parser as input.

This macro creates a wrapper around synchronous or asynchronous functions to automatically parse and pass the clap argument, and will return an error to the shell if it cannot be suitably parsed.

#[derive(Parser, Debug)]
#[clap(author, version, about)]
struct Args {
    // - snip
}

shell.commands.insert("greet", clap_command!((), Args, greet));
shell.commands.insert("greet-async", clap_command!((), Args, async greet_async));

fn greet(_state: &mut (), args: Args) -> Result<(), Box<dyn std::error::Error>> {
    // - snip
}

async fn greet_async(_state: &mut (), args: Args) -> Result<(), Box<std::io::Error>> {
    // - snip
}

NOTE: You need the async crate feature enabled for async clap commands.