Skip to main content

Pipeline

Struct Pipeline 

Source
pub struct Pipeline { /* private fields */ }
Expand description

A builder for creating command pipelines.

§Example

use bare_script::sync::Pipeline;

#[cfg(not(windows))]
{
let output = Pipeline::new("echo")
    .arg("hello world")
    .pipe("grep")
    .arg("hello")
    .execute();
     
assert!(output.is_ok());
}

Implementations§

Source§

impl Pipeline

Source

pub fn new<S: AsRef<OsStr>>(program: S) -> Self

Creates a new pipeline starting with the specified program.

Source

pub fn arg<S: AsRef<OsStr>>(self, arg: S) -> Self

Adds an argument to the last command in the pipeline.

Source

pub fn args<I, S>(self, args: I) -> Self
where I: IntoIterator<Item = S>, S: AsRef<OsStr>,

Adds multiple arguments to the last command in the pipeline.

Source

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.

§Errors

Returns an error if the previous command’s stdout could not be configured for piping.

Source

pub fn env<K, V>(self, key: K, value: V) -> Self
where K: AsRef<OsStr>, V: AsRef<OsStr>,

Sets an environment variable for all commands in the pipeline.

Source

pub fn current_dir<D>(self, dir: D) -> Self
where D: AsRef<Path>,

Sets the working directory for all commands in the pipeline.

Source

pub fn capture_output(self) -> Self

Configures the pipeline to capture the final output.

This must be called before execute() to capture stdout/stderr.

Source

pub fn execute(&mut self) -> ScriptResult<Output>

Executes the pipeline and returns the output of the final command.

§Errors

Returns an error if any command in the pipeline fails to execute.

Trait Implementations§

Source§

impl Debug for Pipeline

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Pipeline

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.