Skip to main content

## Subcommand

# Trait Subcommand

Source

    pub trait Subcommand: Sized + FromArgMatches {
        // Required methods
        fn augment_subcommands(cmd: Command) -> Command;
        fn augment_subcommands_for_update(cmd: Command) -> Command;
        fn has_subcommand(name: &str) -> bool;
    }

Expand description

Parse a sub-command into a user-defined enum.

Implementing this trait lets a parent container delegate subcommand behavior to `Self`. with:

- `#[command(subcommand)] field: SubCmd`: Attribute can be used with either struct fields or enum variants that impl `Subcommand`.
- `#[command(flatten)] Variant(SubCmd)`: Attribute can only be used with enum variants that impl `Subcommand`.

NOTE: Deriving requires the `derive` feature flag

## Required Methods§

Source

#### fn augment_subcommands(cmd: Command) -> Command

Append to `Command` so it can instantiate `Self` via `FromArgMatches::from_arg_matches_mut`

This is used to implement `#[command(flatten)]`

See also `CommandFactory::command`.

Source

#### fn augment_subcommands_for_update(cmd: Command) -> Command

Append to `Command` so it can instantiate `self` via `FromArgMatches::update_from_arg_matches_mut`

This is used to implement `#[command(flatten)]`

See also `CommandFactory::command_for_update`.

Source

#### fn has_subcommand(name: &str) -> bool

Test whether `Self` can parse a specific subcommand

## Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

## Implementations on Foreign Types§

Source§

### impl Subcommand for ()

Source§

#### fn augment_subcommands(cmd: Command) -> Command

Source§

#### fn augment_subcommands_for_update(cmd: Command) -> Command

Source§

#### fn has_subcommand(_name: &str) -> bool

Source§

### impl Subcommand for Infallible

Source§

#### fn augment_subcommands(cmd: Command) -> Command

Source§

#### fn augment_subcommands_for_update(cmd: Command) -> Command

Source§

#### fn has_subcommand(_name: &str) -> bool

Source§

### impl<T> Subcommand for Box<T>
where T: Subcommand,

Source§

#### fn augment_subcommands(cmd: Command) -> Command

Source§

#### fn augment_subcommands_for_update(cmd: Command) -> Command

Source§

#### fn has_subcommand(name: &str) -> bool

## Implementors§