Skip to main content

Command

Trait Command 

Source
pub trait Command: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn description(&self) -> &str;
    fn execute(
        &self,
        args: &str,
        ctx: &mut CommandContext,
    ) -> Result<CommandResult, CliError>;

    // Provided methods
    fn aliases(&self) -> Vec<&str> { ... }
    fn usage(&self) -> Vec<&str> { ... }
}
Expand description

Trait for implementing commands

Required Methods§

Source

fn name(&self) -> &str

Get the command name (e.g., “help”, “session”)

Source

fn description(&self) -> &str

Get command description for help text

Source

fn execute( &self, args: &str, ctx: &mut CommandContext, ) -> Result<CommandResult, CliError>

Execute the command

Provided Methods§

Source

fn aliases(&self) -> Vec<&str>

Get command aliases (e.g., [“?”, “h”] for help)

Source

fn usage(&self) -> Vec<&str>

Get usage examples

Implementors§