pub struct Cmd { /* private fields */ }Expand description
Implementations§
Source§impl Cmd
impl Cmd
Sourcepub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self
pub fn env(self, key: impl Into<OsString>, value: impl Into<OsString>) -> Self
Add one environment variable.
Sourcepub fn env_remove(self, key: impl Into<OsString>) -> Self
pub fn env_remove(self, key: impl Into<OsString>) -> Self
Remove an environment variable (applied after inherited env).
Sourcepub fn env_clear(self) -> Self
pub fn env_clear(self) -> Self
Clear the entire inherited environment; only .env() / .envs() reach the child.
Sourcepub fn stdin(self, data: impl Into<StdinData>) -> Self
pub fn stdin(self, data: impl Into<StdinData>) -> Self
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.
Sourcepub fn stderr(self, mode: Redirection) -> Self
pub fn stderr(self, mode: Redirection) -> Self
Configure stderr routing. Default is Redirection::Capture.
Sourcepub fn deadline(self, deadline: Instant) -> Self
pub fn deadline(self, deadline: Instant) -> Self
Kill if not done by this instant (composes across retries).
Sourcepub fn retry(self, policy: RetryPolicy) -> Self
pub fn retry(self, policy: RetryPolicy) -> Self
Attach a RetryPolicy. Defaults retry up to 3× on transient errors.
Sourcepub fn retry_when(
self,
f: impl Fn(&RunError) -> bool + Send + Sync + 'static,
) -> Self
pub fn retry_when( self, f: impl Fn(&RunError) -> bool + Send + Sync + 'static, ) -> Self
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.
Sourcepub fn secret(self) -> Self
pub fn secret(self) -> Self
Mark this command as containing secrets.
CmdDisplay and RunError render args as <secret> instead of
their values. Useful for docker login, kubectl --token=…, etc.
Sourcepub fn before_spawn<F>(self, hook: F) -> Self
pub fn before_spawn<F>(self, hook: F) -> Self
Register a hook called immediately before each spawn attempt.
Sourcepub fn to_command(&self) -> Command
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.
Sourcepub fn display(&self) -> CmdDisplay
pub fn display(&self) -> CmdDisplay
Snapshot the command for display/logging.
Sourcepub fn spawn(self) -> Result<SpawnedProcess, RunError>
pub fn spawn(self) -> Result<SpawnedProcess, RunError>
Spawn the command as a long-lived process handle.
Returns a SpawnedProcess for streaming, bidirectional protocols,
or any case where you need live access to stdin/stdout. Stdin and
stdout are always piped; stderr follows the configured
Redirection (default Redirection::Capture, drained into a
background thread and surfaced on SpawnedProcess::wait).
If stdin bytes were set via stdin, they’re fed
automatically in a background thread; otherwise the caller can pipe
data via SpawnedProcess::take_stdin.
timeout, deadline, and retry are ignored on this path —
they only apply to the one-shot run method. Use
SpawnedProcess::wait_timeout or SpawnedProcess::kill for
per-call bounds.
Sourcepub fn spawn_and_collect_lines<F>(self, f: F) -> Result<RunOutput, RunError>
pub fn spawn_and_collect_lines<F>(self, f: F) -> Result<RunOutput, RunError>
Spawn and invoke f for each line of stdout as it arrives.
Returns the final RunOutput when the child exits, or a
RunError::NonZeroExit if it exited non-zero. If f returns an
error, the child is killed and the error is surfaced as
RunError::Spawn.
Cmd::new("cargo")
.args(["check", "--message-format=json"])
.spawn_and_collect_lines(|line| {
println!("{line}");
Ok(())
})?;