execx

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 7 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

This section is empty.

Types

type Call

type Call struct {
	Name string
	Args []string
	Dir  string
	Env  []string
}

Call is one recorded invocation.

func (Call) Line

func (c Call) Line() string

type Cmd

type Cmd struct {
	Name  string
	Args  []string
	Dir   string
	Env   []string // extra variables, appended to the current environment
	Stdin io.Reader
	// 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
}

Cmd describes one external command invocation.

func (Cmd) String

func (c Cmd) String() string

type Error

type Error struct {
	Cmd      string
	ExitCode int
	Stderr   string
	Err      error
}

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

Lines renders the recorded calls for assertions.

func (*Fake) Run

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

type OSRunner

type OSRunner struct {
	// Live output goes here; both default to the process streams.
	Stdout io.Writer
	Stderr io.Writer
}

OSRunner runs commands for real.

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
}

Result holds what a finished command produced.

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