pub struct Command {Show 17 fields
pub canonical: String,
pub aliases: Vec<String>,
pub spellings: Vec<String>,
pub summary: String,
pub description: String,
pub arguments: Vec<Argument>,
pub flags: Vec<Flag>,
pub examples: Vec<Example>,
pub subcommands: Vec<Command>,
pub best_practices: Vec<String>,
pub anti_patterns: Vec<String>,
pub semantic_aliases: Vec<String>,
pub handler: Option<HandlerFn>,
pub async_handler: Option<AsyncHandlerFn>,
pub extra: HashMap<String, Value>,
pub exclusive_groups: Vec<Vec<String>>,
pub mutating: bool,
}Expand description
A command in the registry, potentially with subcommands.
Commands are the central unit of argot. Each command has a canonical name,
optional aliases and alternate spellings, human-readable documentation,
typed positional arguments, named flags, usage examples, and an optional
handler closure. Commands can be nested arbitrarily deep via
Command::subcommands.
Use Command::builder to construct instances — direct struct
construction is intentionally not exposed.
§Serialization
Command implements serde::Serialize / Deserialize. The handler
field is skipped during serialization (it cannot be represented in JSON)
and will be None after deserialization.
§Examples
let cmd = Command::builder("deploy")
.alias("d")
.summary("Deploy the app")
.description("Deploys to the specified environment.")
.argument(
Argument::builder("env")
.description("Target environment")
.required()
.build()
.unwrap(),
)
.flag(
Flag::builder("dry-run")
.short('n')
.description("Simulate only")
.build()
.unwrap(),
)
.example(Example::new("deploy to prod", "myapp deploy production"))
.build()
.unwrap();
assert_eq!(cmd.canonical, "deploy");
assert_eq!(cmd.aliases, vec!["d"]);Fields§
§canonical: StringThe primary, canonical name used to invoke this command.
aliases: Vec<String>Alternative names that resolve to this command (e.g. "ls" for "list").
spellings: Vec<String>Alternate capitalizations or spellings (e.g. "LIST" for "list").
Spellings differ from aliases semantically: they represent the same word written differently rather than a short-form abbreviation.
summary: StringOne-line description shown in command listings.
description: StringFull prose description shown in detailed help output.
arguments: Vec<Argument>Ordered list of positional arguments accepted by this command.
flags: Vec<Flag>Named flags (long and/or short) accepted by this command.
examples: Vec<Example>Usage examples shown in help and Markdown documentation.
subcommands: Vec<Command>Nested sub-commands (e.g. remote add, remote remove).
best_practices: Vec<String>Prose tips about correct usage, surfaced to AI agents.
anti_patterns: Vec<String>Prose warnings about incorrect usage, surfaced to AI agents.
semantic_aliases: Vec<String>Natural-language phrases describing what this command does.
Used for intent-based discovery (e.g. crate::query::Registry::match_intent)
but intentionally excluded from normal help output.
handler: Option<HandlerFn>Optional runtime handler invoked by crate::cli::Cli::run.
Skipped during JSON serialization/deserialization.
async_handler: Option<AsyncHandlerFn>Optional async runtime handler (feature: async).
Skipped during JSON serialization.
extra: HashMap<String, Value>Arbitrary application-defined metadata.
Use this to attach structured data that is not covered by the built-in fields (e.g., permission requirements, category tags, telemetry labels).
Serialized to JSON as an object; absent from output when empty.
exclusive_groups: Vec<Vec<String>>Groups of mutually exclusive flag names.
At most one flag in each group may be provided in a single invocation. Validated at build time (flags must exist) and enforced at parse time.
mutating: boolWhether this command mutates state (creates, updates, or deletes resources).
Set to true for commands that are not safe to run freely without
a --dry-run preview first. AI agents use this field to decide
whether they need explicit user confirmation before dispatching.
Use CommandBuilder::mutating to set this field.
§Examples
let cmd = Command::builder("delete")
.summary("Delete a resource")
.mutating()
.build()
.unwrap();
assert!(cmd.mutating);Implementations§
Source§impl Command
impl Command
Sourcepub fn builder(canonical: impl Into<String>) -> CommandBuilder
pub fn builder(canonical: impl Into<String>) -> CommandBuilder
Create a new CommandBuilder with the given canonical name.
§Arguments
canonical— The primary command name. Must be non-empty after trimming (enforced byCommandBuilder::build).
§Examples
let cmd = Command::builder("list").build().unwrap();
assert_eq!(cmd.canonical, "list");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Command
impl<'de> Deserialize<'de> for Command
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Ord for Command
Commands are ordered by canonical name, then by their full field contents.
impl Ord for Command
Commands are ordered by canonical name, then by their full field contents.