Skip to main content

Crate click_derive

Crate click_derive 

Source
Expand description

Derive macros for click-rs CLI library.

This crate provides procedural macros for automatically generating CommandLike implementations from Rust structs.

§Example

use click_derive::Command;

#[derive(Command)]
#[command(name = "greet")]
/// A friendly greeter
struct Greet {
    /// Name to greet
    #[argument]
    name: String,

    /// Number of times to greet
    #[option(short, long, default = 1)]
    count: i32,
}

impl Greet {
    fn run(&self, _ctx: &click::Context) -> click::Result<()> {
        for _ in 0..self.count {
            println!("Hello, {}!", self.name);
        }
        Ok(())
    }
}

Attribute Macros§

command
Attribute macro for function-first command definitions.
group
Attribute macro for function-first group definitions.

Derive Macros§

Command
Derive macro for creating CLI commands from structs.
Group
Derive macro for creating CLI command groups from structs.