pub trait Args: FromArgMatches + Sized {
fn augment_args(cmd: Command) -> Command;
fn augment_args_for_update(cmd: Command) -> Command;
fn group_id() -> Option<Id> { ... }
}
Expand description
Parse a set of arguments into a user-defined container.
Implementing this trait lets a parent container delegate argument parsing behavior to Self
.
with:
#[command(flatten)] args: ChildArgs
: Attribute can only be used with struct fields that implArgs
.Variant(ChildArgs)
: No attribute is used with enum variants that implArgs
.
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(flatten)]
logging: LogArgs,
}
#[derive(clap::Args)]
struct LogArgs {
#[arg(long, short = 'v', action = clap::ArgAction::Count)]
verbose: i8,
}
Required Methods
fn augment_args(cmd: Command) -> Command
fn augment_args(cmd: Command) -> Command
Append to Command
so it can instantiate Self
.
See also CommandFactory
.
fn augment_args_for_update(cmd: Command) -> Command
fn augment_args_for_update(cmd: Command) -> Command
Append to Command
so it can update self
.
This is used to implement #[command(flatten)]
See also CommandFactory
.
Provided Methods
Report the ArgGroup::id
for this set of arguments