execx

package
v0.19.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2026 License: MIT Imports: 9 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 execx wraps os/exec behind an interface, so command sequences can be asserted in tests without git, docker or node being installed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MissingBinary added in v0.10.0

func MissingBinary(err error) string

MissingBinary names the executable a command could not find, or "" for any other failure, so a caller can say where that binary is meant to come from.

func ShellQuote added in v0.7.0

func ShellQuote(s string) string

ShellQuote wraps s in single quotes unless every character is one a shell takes literally, which covers paths, flags and key=value.

func WaitFor added in v0.5.0

func WaitFor(ctx context.Context, r Runner, label string, attempts int, interval time.Duration, probe Cmd) error

WaitFor runs probe until it succeeds, which is how a container is told to be ready: docker reports one started long before what runs inside it answers. The last failure is wrapped, since it is the only thing that says why.

Types

type Call

type Call struct {
	Name string
	Args []string
	Dir  string
	Env  []string
	// Bounded says the context carried a deadline. A command asking docker
	// something must never be able to hang wtm, and nothing could assert that
	// before: the fake used to drop the context on the floor.
	Bounded bool
}

func (Call) Line

func (c Call) Line() string

Line renders the call the way Cmd.String does, so an assertion reads exactly what a failure message would show.

type Cmd

type Cmd struct {
	Name string
	Args []string
	Dir  string
	Env  []string // extra variables, appended to the current environment
	// Stdout, when set, receives the command output instead of it being
	// captured in Result (used to stream pg_dump straight to a file).
	Stdout io.Writer
	// Live mirrors output to the terminal, for long commands like docker build.
	Live bool
	// Interactive hands the process the terminal itself, so that a shell or
	// any prompt-driven command behaves normally. Nothing is captured.
	Interactive bool
}

func (Cmd) String

func (c Cmd) String() string

String renders the command the way a shell would take it back, since wtm prints commands for the user to replay: joined raw, `sh -c "a && b"` reads as two commands and a path with a space as two arguments.

type Error

type Error struct {
	Cmd      string
	ExitCode int
	Stderr   string
	Err      error
	// Live says the output already reached the terminal as the command ran.
	// The error then keeps the last line alone, the diagnosis, rather than
	// printing the whole block a second time.
	Live bool
}

Error carries the underlying command failure so callers can wrap it with their own context without losing the original message.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Fake

type Fake struct {
	Calls   []Call
	Handler func(c Cmd) (Result, error)
}

Fake records commands and replies with whatever Handler returns. It lives in the non-test build so every package can drive its own sequences.

func (*Fake) Lines

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

func (*Fake) Run

func (f *Fake) Run(ctx context.Context, c Cmd) (Result, error)

type OSRunner

type OSRunner struct{}

OSRunner is the production runner. Live output goes to the process streams; a command wanting its output elsewhere sets Cmd.Stdout.

func (OSRunner) Run

func (r OSRunner) Run(ctx context.Context, c Cmd) (Result, error)

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
}

type Runner

type Runner interface {
	Run(ctx context.Context, c Cmd) (Result, error)
}

Runner executes commands. Production code uses OSRunner, tests use Fake.

Jump to

Keyboard shortcuts

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