Skip to main content

Command

Trait Command 

Source
pub trait Command: Parser {
    type Error: BuiltinError + 'static;

    // Required method
    fn execute<SE: ShellExtensions>(
        &self,
        context: ExecutionContext<'_, SE>,
    ) -> impl Future<Output = Result<ExecutionResult, Self::Error>> + Send;

    // Provided methods
    fn new<I>(args: I) -> Result<Self, Error>
       where I: IntoIterator<Item = String> { ... }
    fn takes_plus_options() -> bool { ... }
    fn get_content(
        name: &str,
        content_type: ContentType,
        options: &ContentOptions,
    ) -> Result<String, Error> { ... }
}
Expand description

Trait implemented by built-in shell commands.

Required Associated Types§

Source

type Error: BuiltinError + 'static

The error type returned by the command.

Required Methods§

Source

fn execute<SE: ShellExtensions>( &self, context: ExecutionContext<'_, SE>, ) -> impl Future<Output = Result<ExecutionResult, Self::Error>> + Send

Executes the built-in command in the provided context.

§Arguments
  • context - The context in which the command is being executed.
§Errors

The returned future resolves to Self::Error when the command fails. The conditions are specific to each built-in.

Provided Methods§

Source

fn new<I>(args: I) -> Result<Self, Error>
where I: IntoIterator<Item = String>,

Instantiates the built-in command with the given arguments.

§Arguments
  • args - The arguments to the command.
§Errors

Returns a clap::Error if args do not parse as valid arguments for the command, including unknown options, missing required values, and requests for help or version text.

Source

fn takes_plus_options() -> bool

Returns whether or not the command takes options with a leading ‘+’ or ‘-’ character.

Source

fn get_content( name: &str, content_type: ContentType, options: &ContentOptions, ) -> Result<String, Error>

Returns the textual help content associated with the command.

§Arguments
  • name - The name of the command.
  • content_type - The type of content to retrieve.
  • options - Additional options for content retrieval.
§Errors

Returns error::ErrorKind::Unimplemented for ContentType::ManPage, since man page rendering is not yet implemented.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§