pub struct Command { /* private fields */ }Expand description
A single registered subcommand.
Build with Command::new and configure via the builder methods before
passing to App::add_command.
Implementations§
Source§impl Command
impl Command
Sourcepub fn new(name: impl Into<String>, handler: fn(&CommandContext)) -> Self
pub fn new(name: impl Into<String>, handler: fn(&CommandContext)) -> Self
Creates a new command with the given name and handler function.
The handler receives a CommandContext containing the resolved flags
and positional arguments for this invocation.
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Sets the short description shown in the app-level help listing.
Sourcepub fn usage(self, usage: impl Into<String>) -> Self
pub fn usage(self, usage: impl Into<String>) -> Self
Sets the usage string shown when the user runs <cmd> --help.
Displayed as: <prog> <cmd> <usage>. For example, passing "<file> [--output <path>]"
produces mytool convert <file> [--output <path>].
If omitted and the command has registered flags, a fallback of [options] is shown.
Sourcepub fn strict_flags(self, strict: bool) -> Self
pub fn strict_flags(self, strict: bool) -> Self
Controls whether unknown flags cause a hard error or just a warning.
When true, passing an unrecognized flag prints an error and exits without
calling the handler. When false (the default), a warning is printed and
execution continues. Global flags are always considered known and never
trigger this check.