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 { ... } }

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

type State[src]

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

Loading content...

Required methods

fn name(&self) -> &str[src]

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

fn validate_args(&self, args: &[String]) -> Result<()>[src]

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

Arguments

args - The arguments to validate.

fn execute(&self, state: &mut Self::State, args: &[String]) -> Result<String>[src]

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.

Loading content...

Provided methods

fn autocomplete(&self, _args: Vec<&str>, _trailing_space: bool) -> Completion[src]

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.

fn help(&self) -> String[src]

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

Expected to be relatively brief.

Loading content...

Implementors

impl<'a, S> BaseCommand for Command<'a, S>[src]

type State = S

impl<'a, S> BaseCommand for BasicCommand<'a, S>[src]

type State = S

impl<'a, S> BaseCommand for ExitCommand<'a, S>[src]

type State = Shell<'a, S>

impl<'a, S> BaseCommand for HelpCommand<'a, S>[src]

type State = Shell<'a, S>

impl<'a, S> BaseCommand for HelpTreeCommand<'a, S>[src]

type State = Shell<'a, S>

impl<'a, S> BaseCommand for HistoryCommand<'a, S>[src]

type State = Shell<'a, S>

impl<'a, S> BaseCommand for ParentCommand<'a, S>[src]

type State = S

impl<S> BaseCommand for EchoCommand<S>[src]

type State = S

Loading content...