Skip to main content

Command

Struct Command 

Source
pub struct Command<'a> {
Show 19 fields pub name: &'a str, pub aliases: &'a [&'a str], pub flags: &'a [&'a Flag<'a>], pub args: &'a [&'a Arg<'a>], pub subcommands: &'a [&'a Command<'a>], pub default_subcommand: Option<&'a Command<'a>>, pub external_subcommand: bool, pub arg_required_else_help: bool, pub subcommand_negates_reqs: bool, pub args_conflicts_with_subcommands: bool, pub subcommand_precedence_over_arg: bool, pub allow_missing_positional: bool, pub dont_delimit_trailing_values: bool, pub unknown_flags: Option<UnknownFlags>, pub version: bool, pub disable_help_flag: bool, pub disable_help_subcommand: bool, pub disable_version_flag: bool, pub key: u64,
}
Expand description

A command: its flags, its positional arguments, and its subcommands.

Every field is a borrowed slice so that a derive can emit the whole tree as static data. Use ..Command::EMPTY to fill in the parts you do not need.

Fields§

§name: &'a str

The canonical name, used to select this command.

§aliases: &'a [&'a str]

Alternative names that also select it.

§flags: &'a [&'a Flag<'a>]§args: &'a [&'a Arg<'a>]

Positional arguments, in the order they are filled.

§subcommands: &'a [&'a Command<'a>]§default_subcommand: Option<&'a Command<'a>>

Where a word goes when it names no subcommand of this one.

The spec’s default_subcommand. mise build means mise run build: the word names no command, so the parser descends into run and lets run have it — even where this command declares an argument of its own, which is what makes the property worth having rather than a synonym for a positional.

Applied at most once per parse, so a CLI cannot loop through it, and only where a subcommand could still be selected.

Resolve it with find_subcommand, which turns a name that no subcommand answers to into a compile error.

§external_subcommand: bool

Whether an unmatched word is forwarded as an external command plus the rest of argv.

clap’s allow_external_subcommands. Known subcommands still win; a default_subcommand still catches first. Once the unmatched word is taken, remaining tokens — including --help — are not parsed as this command’s flags.

§arg_required_else_help: bool

Show this command’s help when no argv token follows its name.

This is clap’s arg_required_else_help. It deliberately observes argv rather than bound values: an environment variable or default may fill a field, but neither means the user supplied an argument to this invocation.

§subcommand_negates_reqs: bool

Selecting a subcommand suppresses this command’s required arguments.

§args_conflicts_with_subcommands: bool

Once this command binds a flag or positional, selecting one of its subcommands is an error.

§subcommand_precedence_over_arg: bool

Let a known subcommand interrupt a variadic argument that would otherwise consume it.

§allow_missing_positional: bool

Let a later required positional take a word while an earlier optional positional remains empty.

§dont_delimit_trailing_values: bool

Disable delimiter splitting for positional values after -- or on an automatic trailing argument. Inherited by subcommands.

§unknown_flags: Option<UnknownFlags>

What an unrecognized flag-like token means here, or None to keep whatever the enclosing command said. See UnknownFlags.

Inherited rather than resolved per command, which is what usage-lib does — its effective_unknown_flags walks outward from the command that ran and falls back to the spec’s. Resolving it in the tables instead was possible only for a builder that can see the whole tree: a derive expands one struct at a time and cannot see its parent, so #[usage(unknown_flags = "error")] on the root reached the root alone and a subcommand had no way to say it at all.

The parser carries the effective value down as it descends, so a command that states nothing costs nothing.

§version: bool

Whether this command answers to --version and -V.

Set on the root, and only when the CLI declares a version: clap adds the flag exactly then, and a --version that answers with nothing is worse than one that is not there. A field rather than a rule about depth, so a CLI that wants it on a subcommand — clap’s propagate_version — has somewhere to say so.

§disable_help_flag: bool

Do not synthesize --help and -h for this command.

§disable_help_subcommand: bool

Do not synthesize the help subcommand route for this command.

§disable_version_flag: bool

Do not synthesize --version and -V for this command.

§key: u64

Caller-assigned identifier, echoed back in Event::Command.

Wide enough for a derive to make these unique without coordination: two macro expansions cannot see each other, so the generated keys carry a hash of the type they came from in the high half and a per-type index in the low half. A parse dispatches on this, so a collision would bind the wrong field — Spec::to_kdl checks the tree for duplicates in debug builds.

Implementations§

Source§

impl Command<'_>

Source

pub const EMPTY: Command<'static>

A command with nothing declared, for use with struct update syntax.

Trait Implementations§

Source§

impl<'a> Clone for Command<'a>

Source§

fn clone(&self) -> Command<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Command<'a>

Source§

impl<'a> Debug for Command<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Command<'a>

Source§

impl<'a> PartialEq for Command<'a>

Source§

fn eq(&self, other: &Command<'a>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Command<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Command<'a>

§

impl<'a> RefUnwindSafe for Command<'a>

§

impl<'a> Send for Command<'a>

§

impl<'a> Sync for Command<'a>

§

impl<'a> Unpin for Command<'a>

§

impl<'a> UnsafeUnpin for Command<'a>

§

impl<'a> UnwindSafe for Command<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.