execx

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package execx locates and runs the external tools lo still shells out to. Lookup prefers the project's b-managed toolchain (.bin) over PATH, so lo works without the caller having prepared any environment.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("executable not found")

ErrNotFound is the Runner's error when a tool name resolves nowhere (wrapped as `<name>: executable not found`); errors.Is matches it.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps a Runner error to the subprocess exit code: nil → 0, an *exec.ExitError or anything carrying ExitCode() → its code, anything else (the tool was not found, the context ended) → 1. A child that died of a signal reports 128+n, which is what bash's `$?` shows for it (130 for SIGINT, 143 for SIGTERM); exec.ExitError.ExitCode alone reports -1 there, and -1 reaches os.Exit as 255.

func Look

func Look(p *config.Paths, tool string) (string, bool)

Look resolves tool to an executable path: $PATH_BIN/<tool> when present and executable, else the first PATH hit. ok is false when the tool is nowhere. A nil p skips the .bin step (PATH only — the runner for code that has no project, like the toolchain doctor).

func Output

func Output(ctx context.Context, r Runner, c Cmd) ([]byte, error)

Output runs c through r and returns its stdout — the `$(cmd 2>/dev/null)` shape of the bash ports (and of exec.Cmd.Output, whose stderr capture none of the call sites ever read). Stdin is closed and stderr is discarded unless c sets them. Stdout must be unset.

func PrependPATH

func PrependPATH(dirs ...string) string

PrependPATH returns the process PATH with dirs prepended, in the given order, each only when it is not on PATH already; an empty dir is skipped. It is the one spelling of "the PATH lo prepares for a child" (the bash shim, the provider bridge, recover, the render children).

func TrimNewlines

func TrimNewlines(s string) string

TrimNewlines drops the trailing newlines of s, as a bash command substitution (`$(…)`) does with a tool's output or a file's content.

Types

type Cmd

type Cmd struct {
	// Name is the tool name, resolved via Look (b-managed .bin first, then
	// PATH). A value containing a path separator is used as-is.
	Name string
	Args []string
	// Dir is the working directory ("" = inherit). The kubeone driver
	// depends on this: `kubeone apply` writes <name>-kubeconfig into its
	// CWD, so the apply MUST run inside the work dir.
	Dir string
	// Env entries are appended to the inherited environment.
	Env []string
	// Stdin/Stdout/Stderr default to the process's own when nil.
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

Cmd describes one external process invocation.

type Runner

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

Runner runs external commands. The single seam that lets driver code run hermetically under test (a fake Runner records the Cmd instead of executing).

func NewRunner

func NewRunner(p *config.Paths) Runner

NewRunner builds the default Runner over the resolved project paths.

Jump to

Keyboard shortcuts

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