exec

package
v0.46.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: MIT, MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package exec runs things. One place, so dry-run and output capture are impossible to forget.

Hooks are shell strings, run via `bash -c`, with the resolved spec env injected. That is a deliberate trade: this tool orchestrates other people's CLIs (docker, gcloud, curl, psql), and a structured arg-array API would just push quoting into YAML. Hooks come from a spec file in your own repo — the same trust level as a CI workflow — so this is not a sandbox boundary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureOutputs

func CaptureOutputs(stdout string) (keys []string, values map[string]string)

CaptureOutputs collects `KEY=VALUE` lines from a provision hook's stdout, in order of first appearance (a repeated key keeps its position and takes the last value — JS object semantics).

This is how a provisioned resource hands its coordinates to the rest of the stack — a freshly created database emits `DATABASE_URL=postgres://…` and compose picks it up as an env var. Only SHOUT_CASE keys are captured so ordinary log chatter is ignored.

func EnvList

func EnvList(m map[string]string) []string

EnvList renders a map as KEY=VALUE pairs, sorted so a test can compare them.

func Environ

func Environ() map[string]string

Environ is the process environment as a map.

func Indent

func Indent(s string) string

Indent prefixes every line with ` | `, the verbose transcript shape.

func Merge

func Merge(maps ...map[string]string) map[string]string

Merge overlays b on a into a new map (a later map wins), skipping nothing.

Types

type Fake

type Fake struct {
	Log    []string
	Fail   func(cmd string) bool
	Stdout string
	Answer func(cmd string) (Result, bool)
	// contains filtered or unexported fields
}

Fake is the test runner: records every command, answers from a script, never spawns.

Owner: the test. The mutex is only there so a job goroutine and the asserting test may touch Log.

func NewFake

func NewFake(fail func(cmd string) bool, stdout string) *Fake

NewFake returns a runner whose every command succeeds with `stdout`, except those `fail` names.

func (*Fake) Commands

func (f *Fake) Commands() []string

Commands is a copy of the log.

func (*Fake) Context

func (f *Fake) Context() context.Context

func (*Fake) Cwd

func (f *Fake) Cwd() string

func (*Fake) DryRun

func (f *Fake) DryRun() bool

func (*Fake) Run

func (f *Fake) Run(cmd string, o RunOptions) Result

Run records and answers.

func (*Fake) WithContext

func (f *Fake) WithContext(ctx context.Context) *Fake

WithContext sets the cancellation context.

func (*Fake) WithCwd

func (f *Fake) WithCwd(dir string) *Fake

WithCwd sets the cwd a fake reports.

func (*Fake) WithDryRun

func (f *Fake) WithDryRun(v bool) *Fake

WithDryRun flips the dry-run flag a fake reports.

type Level

type Level string

Level is how chatty a runner is.

const (
	Quiet   Level = "quiet"
	Normal  Level = "normal"
	Verbose Level = "verbose"
)

type Options

type Options struct {
	DryRun bool
	Level  Level
	Cwd    string
	// BaseEnv is the WHOLE environment a command sees (a replacement, never an overlay on the
	// process env — the caller includes PATH). Nil means the process environment.
	BaseEnv map[string]string
	Ctx     context.Context
	// Out is where dry-run and verbose lines go (stdout when nil).
	Out io.Writer
}

Options configure a real runner.

type Result

type Result struct {
	OK     bool
	Code   int
	Stdout string
	Stderr string
	// Skipped is true when the command did not run because of --dry-run.
	Skipped bool
}

Result is what a command came back with.

type RunOptions

type RunOptions struct {
	// Env is merged OVER the runner's base env for this command only.
	Env map[string]string
	// Label is what a non-verbose dry run prints instead of the command.
	Label string
}

RunOptions are the per-command overrides.

type Runner

type Runner interface {
	Run(cmd string, o RunOptions) Result
	DryRun() bool
	// Cwd is the directory commands run in — the deployment directory for a registry-driven run,
	// empty for the CLI (commands run from the shell's directory, as typing them there would).
	// Exposed because compose needs it: pstack writes a derived compose file next to the submitted
	// one and passes that to -f.
	Cwd() string
	// Context is done when the job was cancelled: the CURRENT command is SIGTERMed and every later
	// one is refused.
	Context() context.Context
}

Runner runs shell strings. The one seam every test fakes.

func New

func New(o Options) Runner

New returns the real runner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL