Trait shi::command::BaseCommand[][src]

pub trait BaseCommand {
    type State;
    fn name(&self) -> &str;
fn validate_args(&self, args: &[String]) -> Result<()>;
fn execute(
        &self,
        state: &mut Self::State,
        args: &[String]
    ) -> Result<String>; fn autocomplete(
        &self,
        _args: Vec<&str>,
        _trailing_space: bool
    ) -> Completion { ... }
fn help(&self) -> String { ... } }
Expand description

BaseCommand is the lower-level command trait. It covers many of the behaviors one would expect from a shell command, e.g., a name (name()) or execution (execute()).

It is generic over a State, S, expected to be bound to its containing Shell.

As it may aid in understanding: builtins are in fact BaseCommand’s, where State = Shell<T>.

Associated Types

The State of the command. Expected to be bound to a containing Shell.

Required methods

Returns the name of the command. This is equivalent to how the command would be invoked.

Validates the given arguments, returning a Result<()> indicating the result of validation.

Arguments

args - The arguments to validate.

Executes the command.

Arguments

state - The state to execute with. args - The arguments to the command invocation.

Returns

Result<String> - The result of the execution of this command. If successful, returns a String that represents the output of the command.

Provided methods

Autocompletes a command, given arguments.

The default implementation provides no autocompletion.

Arguments

args - The arguments to autocomplete. trailing_space - A boolean to indicate if there is a trailing space at the end of the line where a user has asked for completion.

Returns

Completion - The completion result.

Returns a String representing the help text of this command. By default, returns nothing.

Expected to be relatively brief.

Implementors