#command-handler #clap #derive #proc-macro

macro clap-handler-derive

A command handler works with clap-derive to generating subcommand handlers

1 unstable release

0.1.0 Jun 22, 2022

#14 in #command-handler

Download history 7/week @ 2024-07-26 14/week @ 2024-08-02 25/week @ 2024-08-09 13/week @ 2024-08-16 23/week @ 2024-08-23 35/week @ 2024-08-30 7/week @ 2024-09-06 8/week @ 2024-09-13 16/week @ 2024-09-20 25/week @ 2024-09-27 11/week @ 2024-10-04 10/week @ 2024-10-11

62 downloads per month
Used in clap-handler

MIT/Apache

10KB
168 lines

clap-handler

A command handler works with clap-derive to generating subcommand handlers.

Example

use clap::{Parser, AppSettings};
use clap_handler::{Handler, handler, Context};

#[derive(Parser, Handler, Debug, Clone)]
#[clap(name = "Your program", author)]
pub struct Arguments {
    #[clap(subcommand)]
    subcommand: Subcommand,
}


#[derive(Parser, Handler, Debug, Clone)]
#[handler_inject(add_something)]
pub enum Subcommand {
    First(FirstSubcommand),
}

impl Subcommand {
    fn add_something(&self, ctx: &mut Context) -> anyhow::Result<()> {
        // insert something
        // ctx.insert(a_struct);
        Ok(())
    }
}

#[derive(Args, Debug, Clone)]
pub struct FirstSubcommand {
    arg: String,
}

#[handler(FirstSubcommand)]
fn handle_first(me: FirstSubcommand) -> anyhow::Result<()> {
    Ok(())
}

fn main() {
    let args = Arguments::parse();
    log::debug!("{:#?}", args);
    args.run().await
}

For more complex examples, see the anni and sswa.

License

Licensed under either of

at your option.

Dependencies

~1.5MB
~37K SLoC