pub struct Command<'a> {Show 20 fields
pub name: &'a str,
pub aliases: &'a [&'a str],
pub flags: &'a [&'a Flag<'a>],
pub args: &'a [&'a Arg<'a>],
pub clause: Option<Clause<'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 strThe 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.
clause: Option<Clause<'a>>A repeatable group of positional arguments, if this command has one.
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: boolWhether 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: boolShow 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: boolSelecting a subcommand suppresses this command’s required arguments.
args_conflicts_with_subcommands: boolOnce this command binds a flag or positional, selecting one of its subcommands is an error.
subcommand_precedence_over_arg: boolLet a known subcommand interrupt a variadic argument that would otherwise consume it.
allow_missing_positional: boolLet a later required positional take a word while an earlier optional positional remains empty.
dont_delimit_trailing_values: boolDisable 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: boolWhether 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: boolDo not synthesize --help and -h for this command.
disable_help_subcommand: boolDo not synthesize the help subcommand route for this command.
disable_version_flag: boolDo not synthesize --version and -V for this command.
key: u64Caller-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.