Trait leo_lang::cli::commands::Command

source ·
pub trait Command {
    type Input;
    type Output;

    // Required methods
    fn prelude(&self, context: Context) -> Result<Self::Input>
       where Self: Sized;
    fn apply(self, context: Context, input: Self::Input) -> Result<Self::Output>
       where Self: Sized;

    // Provided methods
    fn log_span(&self) -> Span { ... }
    fn execute(self, context: Context) -> Result<Self::Output>
       where Self: Sized { ... }
    fn try_execute(self, context: Context) -> Result<()>
       where Self: Sized { ... }
}
Expand description

Base trait for the Leo CLI, see methods and their documentation for details.

Required Associated Types§

source

type Input

If the current command requires running another command beforehand and needs its output result, this is where the result type is defined. Example: type Input: ::Out

source

type Output

Defines the output of this command, which may be used as Input for another command. If this command is not used as a prelude for another command, this field may be left empty.

Required Methods§

source

fn prelude(&self, context: Context) -> Result<Self::Input>
where Self: Sized,

Runs the prelude and returns the Input of the current command.

source

fn apply(self, context: Context, input: Self::Input) -> Result<Self::Output>
where Self: Sized,

Runs the main operation of this command. This function is run within context of ‘execute’ function, which sets logging and timers.

Provided Methods§

source

fn log_span(&self) -> Span

Adds a span to the logger via tracing::span. Because of the specifics of the macro implementation, it is not possible to set the span name with a non-literal i.e. a dynamic variable even if this variable is a &’static str.

source

fn execute(self, context: Context) -> Result<Self::Output>
where Self: Sized,

A wrapper around the apply method. This function sets up tracing, timing, and the context.

source

fn try_execute(self, context: Context) -> Result<()>
where Self: Sized,

Executes command but empty the result. Comes in handy where there’s a need to make match arms compatible while keeping implementation-specific output possible. Errors however are all of the type Error

Implementors§