pub struct Command {
pub program: PathBuf,
pub args: Vec<String>,
pub env: Vec<(String, String)>,
pub cwd: PathBuf,
pub run_id: String,
pub stdin: Stdin,
pub stderr: Stderr,
pub timeout: Option<Duration>,
}Expand description
What to spawn. Named fields rather than six positional arguments, so a call site says which string is the program and which is the run id, and a new knob is a field with a default instead of a break.
Fields§
§program: PathBuf§args: Vec<String>§env: Vec<(String, String)>Extra environment for the child, applied over the inherited one.
cwd: PathBuf§run_id: StringThe caller’s correlation id, echoed on every Event.
stdin: Stdin§stderr: Stderr§timeout: Option<Duration>Give up after this long. None (the default) waits indefinitely — the
right answer for an agent run a user is watching and can stop, and the
wrong one for anything unattended.
Implementations§
Source§impl Command
impl Command
Sourcepub fn new(program: impl Into<PathBuf>) -> Command
pub fn new(program: impl Into<PathBuf>) -> Command
A run of program, in the current directory, with stdin closed.
The program is the only thing a spawn cannot default, so it is the only argument. Everything else is a named method — three bare strings in a row read as “which one was the cwd again?”.
Sourcepub fn cwd(self, cwd: impl Into<PathBuf>) -> Command
pub fn cwd(self, cwd: impl Into<PathBuf>) -> Command
Where the child runs. Defaults to the current directory.
Sourcepub fn run_id(self, run_id: impl Into<String>) -> Command
pub fn run_id(self, run_id: impl Into<String>) -> Command
A correlation id echoed on every Event, for a caller
multiplexing several runs through one callback. Defaults to empty —
with one run the handle already identifies it.
Sourcepub fn args<I, S>(self, args: I) -> Command
pub fn args<I, S>(self, args: I) -> Command
.args(["--stdio"]) — anything string-like, borrowed or owned.
Sourcepub fn env<I, K, V>(self, env: I) -> Command
pub fn env<I, K, V>(self, env: I) -> Command
.env([("RUST_LOG", "info")]) — applied over the inherited environment.
Sourcepub fn stdin(self, stdin: Stdin) -> Command
pub fn stdin(self, stdin: Stdin) -> Command
What the child’s stdin is connected to. stdout and stderr are always
piped — streaming them is what this crate is for — and arrive as
Event::Stdout / Event::Stderr.
Sourcepub fn stderr(self, stderr: Stderr) -> Command
pub fn stderr(self, stderr: Stderr) -> Command
Whether the child’s stderr is streamed or thrown away.
Sourcepub fn timeout(self, timeout: Duration) -> Command
pub fn timeout(self, timeout: Duration) -> Command
Stop the child if it is still running after timeout, the same way
ProcessHandle::cancel would — so it exits cancelled: true rather
than hanging a caller that has nobody to press stop.
Sourcepub fn start(self) -> Result<(ProcessHandle, Receiver<Event>), StreamError>
pub fn start(self) -> Result<(ProcessHandle, Receiver<Event>), StreamError>
Run it, reading events off a channel.
The channel closes on its own when the run ends: the forwarding closure
is the only owner of the Sender, and it drops with the reader threads.
Sourcepub fn stream<F>(self, callback: F) -> Result<ProcessHandle, StreamError>
pub fn stream<F>(self, callback: F) -> Result<ProcessHandle, StreamError>
Run it, pushing each event to callback as it happens — for a caller
forwarding straight onto a sink rather than looping.
Trait Implementations§
Source§impl ResolveCli for Command
impl ResolveCli for Command
Source§fn resolve_cli(self) -> Self
fn resolve_cli(self) -> Self
PATH. Read more