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 ¶
- func CaptureOutputs(stdout string) (keys []string, values map[string]string)
- func EnvList(m map[string]string) []string
- func Environ() map[string]string
- func Indent(s string) string
- func Merge(maps ...map[string]string) map[string]string
- type Fake
- func (f *Fake) Commands() []string
- func (f *Fake) Context() context.Context
- func (f *Fake) Cwd() string
- func (f *Fake) DryRun() bool
- func (f *Fake) Run(cmd string, o RunOptions) Result
- func (f *Fake) WithContext(ctx context.Context) *Fake
- func (f *Fake) WithCwd(dir string) *Fake
- func (f *Fake) WithDryRun(v bool) *Fake
- type Level
- type Options
- type Result
- type RunOptions
- type Runner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CaptureOutputs ¶
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.
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 ¶
NewFake returns a runner whose every command succeeds with `stdout`, except those `fail` names.
func (*Fake) WithContext ¶
WithContext sets the cancellation context.
func (*Fake) WithDryRun ¶
WithDryRun flips the dry-run flag a fake reports.
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.