command

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package command runs external programs behind an interface.

It exists so that callers of git and kustomize can be tested without either binary present, and so that every subprocess in this repository is context-aware by construction.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotInstalled = errors.New("not installed")

ErrNotInstalled reports that a required external binary is not on PATH. It maps to exit code 127.

Functions

func RequireBinaries

func RequireBinaries(names ...string) error

RequireBinaries checks that every named binary is on PATH, so a run fails immediately with one clear message naming all of them rather than part-way through after the worktree has already been mutated.

Types

type ExecRunner

type ExecRunner struct {
	// Env holds NAME=VALUE pairs added to the environment of every command it
	// runs, overriding the parent's. It exists so a caller can pin the parts of
	// a tool's behaviour that would otherwise come from whatever the user's shell
	// happens to export — git's terminal prompting above all, which would
	// otherwise wait for input on a tty whose output this package captures.
	Env []string
}

ExecRunner runs commands as subprocesses.

func (ExecRunner) Run

func (r ExecRunner) Run(ctx context.Context, dir, name string, args ...string) ([]byte, []byte, error)

Run implements Runner using exec.CommandContext, so cancelling ctx kills the child. That matters here: this package shells out to `git push` over SSH and can sit in an ArgoCD poll for minutes, and with a context-free exec.Command a Ctrl-C would cancel the Go side while the subprocess kept running.

type ExitError

type ExitError struct {
	Name   string
	Args   []string
	Dir    string
	Code   int
	Stderr string
}

ExitError reports a command that ran and failed. Stderr is carried verbatim because git and kustomize both explain themselves well and paraphrasing their messages loses detail.

func (*ExitError) Error

func (e *ExitError) Error() string

type NotInstalledError

type NotInstalledError struct {
	Binary string
	Hint   string
}

NotInstalledError names the missing binary and how to get it.

func (*NotInstalledError) Error

func (e *NotInstalledError) Error() string

func (*NotInstalledError) Unwrap

func (e *NotInstalledError) Unwrap() error

type Runner

type Runner interface {
	// Run executes name with args in dir, returning its captured stdout and
	// stderr. A non-zero exit is an error; stdout and stderr are still
	// returned so callers can inspect them.
	Run(ctx context.Context, dir, name string, args ...string) (stdout, stderr []byte, err error)
}

Runner runs an external command. It exists so the git and kustomize call sites can be tested without either binary present, and so every subprocess in this package is context-aware by construction.

Jump to

Keyboard shortcuts

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