pub struct Pipeline { /* private fields */ }Expand description
A builder for creating asynchronous command pipelines.
§Example
use bare_script::proc::Pipeline;
#[tokio::main]
async fn main() -> Result<(), bare_script::ScriptError> {
let output = Pipeline::new("echo")
.arg("hello world")
.pipe("grep")
.arg("hello")
.execute()
.await?;
assert!(output.success());
Ok(())
}Implementations§
Source§impl Pipeline
impl Pipeline
Sourcepub fn new<S: AsRef<OsStr>>(program: S) -> Self
pub fn new<S: AsRef<OsStr>>(program: S) -> Self
Creates a new pipeline starting with the specified program.
Sourcepub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self
Adds an argument to the last command in the pipeline.
Sourcepub fn args<I, S>(self, args: I) -> Self
pub fn args<I, S>(self, args: I) -> Self
Adds multiple arguments to the last command in the pipeline.
Sourcepub fn pipe<S: AsRef<OsStr>>(self, program: S) -> Self
pub fn pipe<S: AsRef<OsStr>>(self, program: S) -> Self
Adds a new command to the pipeline, piping the output of the previous command to the stdin of this command.
Sourcepub fn env<K, V>(self, key: K, value: V) -> Self
pub fn env<K, V>(self, key: K, value: V) -> Self
Sets an environment variable for all commands in the pipeline.
Sourcepub fn current_dir<D>(self, dir: D) -> Self
pub fn current_dir<D>(self, dir: D) -> Self
Sets the working directory for all commands in the pipeline.
Sourcepub fn capture_output(self) -> Self
pub fn capture_output(self) -> Self
Configures the pipeline to capture the final output.
Sourcepub async fn execute(&mut self) -> ScriptResult<Output>
pub async fn execute(&mut self) -> ScriptResult<Output>
Executes the pipeline asynchronously and returns the output of the final command.
Note: For async pipelines, commands are executed sequentially, with each command’s stdout passed to the next command’s stdin.
§Errors
Returns an error if any command in the pipeline fails to execute.