Skip to main content

CommandLike

Trait CommandLike 

Source
pub trait CommandLike: Send + Sync {
    // Required methods
    fn name(&self) -> Option<&str>;
    fn make_context(
        &self,
        info_name: &str,
        args: Vec<String>,
        parent: Option<Arc<Context>>,
    ) -> Result<Context, ClickError>;
    fn invoke(&self, ctx: &Context) -> Result<(), ClickError>;
    fn main(&self, args: Vec<String>) -> Result<(), ClickError>;
    fn get_help(&self, ctx: &Context) -> String;
    fn get_short_help(&self) -> String;
    fn is_hidden(&self) -> bool;
    fn get_usage(&self, ctx: &Context) -> String;
    fn as_any(&self) -> &dyn Any;
}
Expand description

Shared interface for Command and Group.

This trait provides a common interface that both Command and Group implement, allowing them to be used interchangeably in many contexts.

Required Methods§

Source

fn name(&self) -> Option<&str>

Get the name of this command.

Source

fn make_context( &self, info_name: &str, args: Vec<String>, parent: Option<Arc<Context>>, ) -> Result<Context, ClickError>

Create a context for executing this command.

§Arguments
  • info_name - The name to display in help/usage
  • args - The arguments to parse
  • parent - Optional parent context for nested commands
Source

fn invoke(&self, ctx: &Context) -> Result<(), ClickError>

Invoke the command with the given context.

Source

fn main(&self, args: Vec<String>) -> Result<(), ClickError>

Main entry point - make context, parse args, and invoke.

Source

fn get_help(&self, ctx: &Context) -> String

Get the full help text for this command.

Source

fn get_short_help(&self) -> String

Get the short help text for command listings.

Source

fn is_hidden(&self) -> bool

Check if this command is hidden from help output.

Source

fn get_usage(&self, ctx: &Context) -> String

Get the usage line for this command.

Source

fn as_any(&self) -> &dyn Any

Convert to Any for downcasting.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§