Documentation
¶
Overview ¶
Package subprocess contains code to exec subprocesses.
Index ¶
- func MustPipeTo(ctx context.Context, dryRun bool, stdin []byte, argv0 string, args ...string)
- func MustPipeline(ctx context.Context, dryRun bool, stages ...[]string)
- func MustRun(ctx context.Context, dryRun bool, argv0 string, args ...string)
- func MustRunTolerant(ctx context.Context, dryRun bool, argv0 string, args ...string)
- func PipeTo(ctx context.Context, dryRun bool, stdin []byte, argv0 string, args ...string) error
- func Pipeline(ctx context.Context, dryRun bool, stages ...[]string) error
- func Run(ctx context.Context, dryRun bool, argv0 string, args ...string) error
- func RunTolerant(ctx context.Context, dryRun bool, argv0 string, args ...string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustPipeTo ¶
MustPipeTo is like PipeTo but logs and exits on failure.
func MustPipeline ¶
MustPipeline is like Pipeline but logs and exits on failure.
func MustRunTolerant ¶
MustRunTolerant is like RunTolerant but logs and exits on failure.
func PipeTo ¶
PipeTo runs the command represented by argv, piping stdin to its standard input. The argv0 resolves through the deps.All allowlist just like Run.
When dryRun is true, PipeTo prints a round-trippable shell snippet to stdout: the command followed by a heredoc containing stdin, using a random heredoc terminator to avoid collisions with the payload. Pasting the output into a shell reproduces the effect of a live run.
func Pipeline ¶
Pipeline runs a shell-style pipeline of commands wired with pipes. Each stage is an argv slice whose first element must be a command name in deps.All. The first stage's stdin is not connected; the last stage's stdout goes to env.Stdout; every stage's stderr goes to env.Stderr.
When dryRun is true, Pipeline prints a single shell line with the stages joined by " | ".
In live mode, all stages are started concurrently and connected via io.Pipe instances. When a stage exits, its downstream pipe writer is closed (thus sending EOF to the next stage) while its upstream reader is closed (thus sending broken-pipe to the previous stage). The returned error joins stage errors using errors.Join.
This function panics if any stage contains zero entries.
The combined pipeline stdout is the stdout exposed by *testable.Environ while the combined pipeline stdin is /dev/null.
func Run ¶
Run runs the command represented by the given argv.
The argv0 must be a bare command name in deps.All; Run resolves it to an absolute path via deps.LookPath before execution.
When the dryRun argument is true the command is not executed but rather the command that would be executed is printed on stdout. Dry-run does not resolve or enforce the allowlist because it has no side effects.
func RunTolerant ¶
RunTolerant is like Run but suppresses non-zero exit codes, mirroring the shell idiom "cmd || true". Setup errors (command not in the allowlist, LookPath failure) are still reported.
When dryRun is true, the rendered shell line includes a trailing "|| true".
Types ¶
This section is empty.