Skip to main content

Group

Derive Macro Group 

Source
#[derive(Group)]
{
    // Attributes available to this derive:
    #[group]
    #[option]
    #[argument]
    #[subcommand]
    #[pass_context]
    #[pass_obj]
    #[help_option]
}
Expand description

Derive macro for creating CLI command groups from structs.

§Container Attributes

  • #[group(name = "...")] - Set the group name
  • #[group(help = "...")] - Set the help text
  • #[group(run)] - Wire Self::run(&self|self, &Context) -> Result<()> as callback
  • #[group(chain)] - Enable command chaining
  • #[group(invoke_without_command)] - Run callback even without subcommand

§Field Attributes

  • #[subcommand] - Mark field as a subcommand

§Example

#[derive(Group)]
#[group(name = "cli")]
struct Cli {
    #[option(short, long)]
    verbose: bool,

    #[subcommand]
    command: Commands,
}

enum Commands {
    Add(AddCmd),
    Remove(RemoveCmd),
}