Skip to main content

Cmd

Struct Cmd 

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

Builder for a subprocess invocation.

Construct via Cmd::new, configure with builder methods, terminate with Cmd::run. Every knob composes with every other — timeout + env + retry

  • stdin work together without combinatorial API explosion.

Implementations§

Source§

impl Cmd

Source

pub fn new(program: impl Into<OsString>) -> Cmd

Start a new command with the given program.

Source

pub fn arg(self, arg: impl Into<OsString>) -> Cmd

Append a single argument.

Source

pub fn args<I, S>(self, args: I) -> Cmd
where I: IntoIterator<Item = S>, S: Into<OsString>,

Append arguments.

Source

pub fn in_dir(self, dir: impl AsRef<Path>) -> Cmd

Set the working directory.

Source

pub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Cmd

Add one environment variable.

Source

pub fn envs<I, K, V>(self, vars: I) -> Cmd
where I: IntoIterator<Item = (K, V)>, K: Into<OsString>, V: Into<OsString>,

Add multiple environment variables.

Source

pub fn env_remove(self, key: impl Into<OsString>) -> Cmd

Remove an environment variable (applied after inherited env).

Source

pub fn env_clear(self) -> Cmd

Clear the entire inherited environment; only .env() / .envs() reach the child.

Source

pub fn stdin(self, data: impl Into<StdinData>) -> Cmd

Feed data into the child’s stdin.

Accepts Vec<u8>, &[u8], String, &str, or StdinData::from_reader for streaming input. Owned bytes are re-fed on each retry; readers are one-shot.

Source

pub fn stderr(self, mode: Redirection) -> Cmd

Configure stderr routing. Default is Redirection::Capture.

Source

pub fn timeout(self, timeout: Duration) -> Cmd

Kill this attempt after the given duration.

Source

pub fn deadline(self, deadline: Instant) -> Cmd

Kill if not done by this instant (composes across retries).

Source

pub fn retry(self, policy: RetryPolicy) -> Cmd

Attach a RetryPolicy. Defaults retry up to 3× on transient errors.

Source

pub fn retry_when( self, f: impl Fn(&RunError) -> bool + Send + Sync + 'static, ) -> Cmd

Replace the retry predicate without changing the backoff schedule.

If no RetryPolicy is set yet, this installs the default policy and then overrides its predicate.

Source

pub fn secret(self) -> Cmd

Mark this command as containing secrets.

CmdDisplay and RunError render args as <secret> instead of their values. Useful for docker login, kubectl --token=…, etc.

Source

pub fn before_spawn<F>(self, hook: F) -> Cmd
where F: Fn(&mut Command) -> Result<(), Error> + Send + Sync + 'static,

Register a hook called immediately before each spawn attempt.

Source

pub fn to_command(&self) -> Command

Build a raw std::process::Command mirroring this Cmd’s configuration.

Escape hatch for cases procpilot’s builder doesn’t cover. Does not apply stdin data, timeout, retry, or stderr redirection — those are runner-level concerns.

Source

pub fn display(&self) -> CmdDisplay

Snapshot the command for display/logging.

Source

pub fn run(self) -> Result<RunOutput, RunError>

Run the command, blocking until it completes (or times out).

Trait Implementations§

Source§

impl Debug for Cmd

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Cmd

§

impl !RefUnwindSafe for Cmd

§

impl Send for Cmd

§

impl Sync for Cmd

§

impl Unpin for Cmd

§

impl UnsafeUnpin for Cmd

§

impl !UnwindSafe for Cmd

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.