//! Command execution abstraction. //! //! The [`CommandRunner`] trait provides a uniform interface for executing //! commands either locally (via [`LocalRunner`]) or remotely through a //! parent [`Backend`] (via [`RemoteRunner`]). //! //! This abstraction is the key enabler for **path chaining**: backends like //! Docker, Kubernetes, and Sudo use a `CommandRunner` to execute their //! wrapped commands. When used standalone, they get a [`LocalRunner`]; //! when chained behind another hop (e.g. SSH), they get a [`RemoteRunner`] //! that delegates through the parent backend's `exec` method. use async_trait::async_trait; use bytes::Bytes; use std::process::Stdio; use std::sync::Arc; use tokio::io::AsyncWriteExt; use super::{Backend, ExecResult}; use crate::errors::{TrampError, TrampResult}; // --------------------------------------------------------------------------- // Trait // --------------------------------------------------------------------------- /// A provider capable of executing commands and returning their output. #[async_trait] pub trait CommandRunner: Send + Sync { /// Execute `program` with `args` and collect stdout/stderr. async fn run(&self, program: &str, args: &[&str]) -> TrampResult; /// Execute a shell script via `sh -c '