Skip to main content

Command

Struct Command 

Source
pub struct Command { /* private fields */ }

Implementations§

Source§

impl Command

Source

pub fn new(value: impl AsRef<OsStr>) -> Self

Source

pub fn argument(self, value: impl AsRef<OsStr>) -> Self

Source

pub fn optional_argument(self, optional: Option<impl AsRef<OsStr>>) -> Self

Source

pub fn optional_flag(self, condition: bool, flag: impl AsRef<OsStr>) -> Self

Adds a flag argument only if the condition is true.

let verbose = true;
cmd_proc::Command::new("echo")
    .optional_flag(verbose, "--verbose");
Source

pub fn option(self, name: impl AsRef<OsStr>, value: impl AsRef<OsStr>) -> Self

Adds a CLI option (name + value).

cmd_proc::Command::new("git")
    .option("--message", "hello");
// equivalent to: .argument("--message").argument("hello")
Source

pub fn optional_option( self, name: impl AsRef<OsStr>, value: Option<impl AsRef<OsStr>>, ) -> Self

Adds a CLI option (name + value) only if the value is Some.

cmd_proc::Command::new("git")
    .optional_option("--author", Some("Alice"));
// adds "--author Alice" only if Some
Source

pub fn arguments<T: AsRef<OsStr>>( self, value: impl IntoIterator<Item = T>, ) -> Self

Source

pub fn working_directory(self, dir: impl AsRef<Path>) -> Self

Source

pub fn env(self, key: &EnvVariableName<'_>, val: impl AsRef<OsStr>) -> Self

Source

pub fn envs<'a, I, V>(self, vars: I) -> Self
where I: IntoIterator<Item = (EnvVariableName<'a>, V)>, V: AsRef<OsStr>,

Source

pub fn env_remove(self, key: &EnvVariableName<'_>) -> Self

Remove an environment variable from the child process.

Source

pub fn stdin_bytes(self, data: impl Into<Vec<u8>>) -> Self

Source

pub fn stdout_capture(self) -> CaptureSingle<Stdout>

Capture stdout from this command.

Source

pub fn stderr_capture(self) -> CaptureSingle<Stderr>

Capture stderr from this command.

Source

pub fn stdout_null(self) -> Self

Redirect stdout to /dev/null.

Source

pub fn stderr_null(self) -> Self

Redirect stderr to /dev/null.

Source

pub fn stdout_inherit(self) -> Self

Inherit stdout from the parent process (default).

Source

pub fn stderr_inherit(self) -> Self

Inherit stderr from the parent process (default).

Source

pub fn build(self) -> Command

Consume the builder and return the underlying tokio::process::Command.

Use this when you need full control over the child process (e.g. interactive stdin/stdout piping) beyond what the capture API provides.

Source

pub async fn status(self) -> Result<(), CommandError>

Execute the command and return success or an error.

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.