Trait deepl::parse_arguments::Subcommand
source · [−]pub trait Subcommand: FromArgMatches {
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 implSubcommand
.#[command(flatten)] Variant(SubCmd)
: Attribute can only be used with enum variants that implSubcommand
.
See the derive reference for attributes and best practices.
NOTE: Deriving requires the [derive
feature flag][crate::_features]
Example
#[derive(clap::Parser)]
struct Args {
#[command(subcommand)]
action: Action,
}
#[derive(clap::Subcommand)]
enum Action {
Add,
Remove,
}
Required Methods
sourcefn augment_subcommands(cmd: Command) -> Command
fn augment_subcommands(cmd: Command) -> Command
Append to Command
so it can instantiate Self
.
See also CommandFactory
.
sourcefn augment_subcommands_for_update(cmd: Command) -> Command
fn augment_subcommands_for_update(cmd: Command) -> Command
Append to Command
so it can update self
.
This is used to implement #[command(flatten)]
See also CommandFactory
.
sourcefn has_subcommand(name: &str) -> bool
fn has_subcommand(name: &str) -> bool
Test whether Self
can parse a specific subcommand