Skip to main content

CommandRunner

Trait CommandRunner 

Source
pub trait CommandRunner: Send + Sync {
    // Required method
    fn run(
        &self,
        program: &str,
        args: &[&str],
        cwd: &Path,
    ) -> Result<CommandOutput, CommandError>;

    // Provided methods
    fn run_with_timeout(
        &self,
        program: &str,
        args: &[&str],
        cwd: &Path,
        _timeout: Duration,
    ) -> Result<CommandOutput, CommandError> { ... }
    fn run_quiet(
        &self,
        program: &str,
        args: &[&str],
        cwd: &Path,
        timeout: Duration,
    ) -> Result<CommandOutput, CommandError> { ... }
}
Expand description

Trait for executing subprocess commands.

Required Methods§

Source

fn run( &self, program: &str, args: &[&str], cwd: &Path, ) -> Result<CommandOutput, CommandError>

Provided Methods§

Source

fn run_with_timeout( &self, program: &str, args: &[&str], cwd: &Path, _timeout: Duration, ) -> Result<CommandOutput, CommandError>

Run a command with a hard wall-clock timeout. If the process does not exit before timeout elapses it is killed and CommandError::TimedOut is returned.

The default implementation ignores timeout and delegates to Self::run. Implementors that control a real subprocess should override this with an actual deadline check.

Source

fn run_quiet( &self, program: &str, args: &[&str], cwd: &Path, timeout: Duration, ) -> Result<CommandOutput, CommandError>

Like Self::run_with_timeout, but for an internal existence/probe check whose stderr looks like a failure on the common path (e.g. npm view against an unpublished package prints a 404-shaped “not found” to stderr normally) – unlike a real, user-facing mutating command, this must not stream that noise live to the terminal, only capture it into CommandOutput for the caller to classify.

Default implementation just delegates to Self::run_with_timeout (streams live); implementors doing their own live-streaming should override this to suppress it for probe calls.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§