Skip to main content

CliRunner

Trait CliRunner 

Source
pub trait CliRunner: Send + Sync {
    // Required methods
    fn run<'life0, 'life1, 'async_trait>(
        &'life0 self,
        cmd: &'life1 str,
        args: Vec<String>,
    ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn run_with_env<'life0, 'life1, 'async_trait>(
        &'life0 self,
        cmd: &'life1 str,
        args: Vec<String>,
        env: Vec<(String, String)>,
    ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn tool_exists(&self, name: &str) -> bool;
}
Expand description

Abstraction over external command execution.

Production code uses DefaultCliRunner; tests swap in MockCliRunner.

Required Methods§

Source

fn run<'life0, 'life1, 'async_trait>( &'life0 self, cmd: &'life1 str, args: Vec<String>, ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Run an external command and return its captured stdout.

Implementations MUST forward the call through tokio::task::spawn_blocking (or equivalent) so that the async runtime is never blocked.

Source

fn run_with_env<'life0, 'life1, 'async_trait>( &'life0 self, cmd: &'life1 str, args: Vec<String>, env: Vec<(String, String)>, ) -> Pin<Box<dyn Future<Output = Result<String, Error>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Run an external command with additional environment variables and return its captured stdout.

Entries in env are added to the inherited environment of the current process. This is used, for example, to pass SSH_ASKPASS when loading passphrase-protected keys.

Implementations MUST forward the call through tokio::task::spawn_blocking (or equivalent) so that the async runtime is never blocked.

Source

fn tool_exists(&self, name: &str) -> bool

Return true when the given tool is available on PATH.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§