Skip to main content

Command

Trait Command 

Source
pub trait Command<Ctx>: 'static {
    // Required methods
    fn name(&self) -> &str;
    fn help(&self) -> &str;
    fn run(
        &mut self,
        args: &[&str],
        ctx: &mut Ctx,
        out: &mut ConsoleWriter,
    ) -> Result<(), Error>;

    // Provided methods
    fn long_help(&self) -> String { ... }
    fn arg_choices(&self, arg_index: usize) -> &[&'static str] { ... }
    fn arg_choices_ctx<'a>(
        &'a self,
        arg_index: usize,
        prior: &[&str],
    ) -> &'a [&'static str] { ... }
    fn arg_value_choices(&self, arg_index: usize, key: &str) -> &[&'static str] { ... }
    fn arg_value_choices_ctx<'a>(
        &'a self,
        arg_index: usize,
        key: &str,
        prior: &[&str],
    ) -> &'a [&'static str] { ... }
}

Required Methods§

Source

fn name(&self) -> &str

Source

fn help(&self) -> &str

Source

fn run( &mut self, args: &[&str], ctx: &mut Ctx, out: &mut ConsoleWriter, ) -> Result<(), Error>

Recoverable issues go to out.error(..); unrecoverable ones return Err.

Provided Methods§

Source

fn long_help(&self) -> String

\n breaks paint as separate scrollback entries.

Source

fn arg_choices(&self, arg_index: usize) -> &[&'static str]

Source

fn arg_choices_ctx<'a>( &'a self, arg_index: usize, prior: &[&str], ) -> &'a [&'static str]

prior is the arg tokens before the cursor.

Source

fn arg_value_choices(&self, arg_index: usize, key: &str) -> &[&'static str]

key carries no trailing =; empty means free-form.

Source

fn arg_value_choices_ctx<'a>( &'a self, arg_index: usize, key: &str, prior: &[&str], ) -> &'a [&'static str]

Implementors§

Source§

impl<Ctx> Command<Ctx> for SubcommandSet<Ctx>
where Ctx: 'static,

Source§

impl<Ctx, F> Command<Ctx> for FnCommand<F>
where F: FnMut(&[&str], &mut Ctx, &mut ConsoleWriter) -> Result<(), Error> + 'static,