Skip to content

Repository files navigation

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)]pubstructArguments{#[clap(subcommand)]subcommand:Subcommand,}#[derive(Parser,Handler,Debug,Clone)]#[handler_inject(add_something)]pubenumSubcommand{First(FirstSubcommand),}implSubcommand{fnadd_something(&self,ctx:&mutContext) -> anyhow::Result<()>{// insert something// ctx.insert(a_struct);Ok(())}}#[derive(Args,Debug,Clone)]pubstructFirstSubcommand{arg:String,}#[handler(FirstSubcommand)]fnhandle_first(me:FirstSubcommand) -> anyhow::Result<()>{Ok(())}fnmain(){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.

About

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

Resources

Stars

0 stars

Watchers

1 watching

Forks

Used by

Contributors

Languages