Skip to main content

Module exec

Module exec 

Source
Expand description

The single shell-out primitive.

Every external command a step-graph tool runs goes through run (or one of its variants) so command execution is logged + classified in one place. A sequential orchestrator gains nothing from async here, so this is deliberately synchronous std::process, which keeps step bodies plain.

Hang protection: commands that can block indefinitely on the network (curl) pass their own bounding flags (--max-time, --connect-timeout).

Long steps (package installs, clones, builds) also have a streaming variant, run_streamed, which pipes the child’s stdout+stderr and hands each line to a callback as it arrives so a live UI can show real activity instead of a bare spinner. The plain run stays for the many short commands where all-at-once capture is simpler. run_cmd and run_streamed_cmd take a pre-built Command for callers that set a working directory or environment.

Structs§

CmdResult
Outcome of one external command. code is None when the process could not be spawned at all (binary missing on PATH); spawned distinguishes that from a non-zero exit.

Functions§

run
Run program args..., capturing stdout/stderr. Never panics: a spawn failure (missing binary) yields a CmdResult { code: None, spawned: false } rather than an error, so callers decide whether a missing tool is fatal.
run_checked
Run a command that MUST succeed; returns the captured result or an error carrying the trimmed stderr. Use inside Required steps.
run_cmd
Like run but takes a pre-built Command (so the caller can set the working directory + environment) and captures the FULL stdout/stderr with no line cap: use when the output is parsed and may be long (e.g. a PEM key), unlike the streaming runners which keep only a bounded tail.
run_ok
Convenience: run and report only whether it exited 0. Use for best-effort commands where the output is not needed.
run_streamed
Run program args..., streaming each stdout/stderr line to on_line as it arrives. Returns the same CmdResult shape as run, but stdout / stderr carry only the trailing 120 lines of each stream (so an anyhow::bail!(…, res.stderr.trim()) caller still reports the real error). on_line runs on the calling thread, so it can borrow non-Send state (the progress sink) freely.
run_streamed_cmd
Like run_streamed but takes a pre-built Command, so the caller can set the working directory + environment. Streams stdout/stderr lines to on_line on the calling thread.
run_with_stdin
Run program args... with input written to its stdin, capturing stdout/stderr like run. For secrets a command can read from stdin (a Wi-Fi passphrase), so they never appear in the process argv (readable by every local user through /proc/<pid>/cmdline) or in this module’s logs: input is never logged.