exec

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package exec wraps os/exec with consistent error handling for external command execution. Every initech package that shells out to git, bd, or other tools uses the Runner interface from this package instead of calling os/exec directly.

This indirection is the primary testing seam for the entire project. Tests swap in a fake Runner to verify command invocations without requiring real git or bd installations. The DefaultRunner implementation shells out to real binaries via os/exec.

All methods return combined stdout+stderr output as a trimmed string. Errors wrap the underlying exec error with the command name and captured stderr for diagnostics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultRunner

type DefaultRunner struct{}

DefaultRunner shells out to real binaries via os/exec. Safe for concurrent use (each call creates an independent exec.Cmd).

func (*DefaultRunner) Run

func (r *DefaultRunner) Run(name string, args ...string) (string, error)

Run executes a command in the caller's working directory.

func (*DefaultRunner) RunInDir

func (r *DefaultRunner) RunInDir(dir, name string, args ...string) (string, error)

RunInDir executes a command in the specified directory. If dir is empty, the caller's working directory is used.

type FakeRunner

type FakeRunner struct {
	// Calls records each invocation as "dir|name arg1 arg2".
	// Dir is empty string when Run (not RunInDir) was used.
	Calls []string

	// Output is returned for every call. Set per-test.
	Output string

	// Err is returned for every call. Set per-test.
	Err error
}

FakeRunner records commands for testing downstream packages. It implements Runner by recording each call and returning configured Output and Err values.

Not used in production. Exists so packages like git, scaffold, and other tools can test their command invocations without shelling out.

func (*FakeRunner) Run

func (f *FakeRunner) Run(name string, args ...string) (string, error)

Run records the call and returns the configured output and error.

func (*FakeRunner) RunInDir

func (f *FakeRunner) RunInDir(dir, name string, args ...string) (string, error)

RunInDir records the call with directory context and returns configured output and error.

type Runner

type Runner interface {
	// Run executes a command in the caller's working directory.
	// Returns combined stdout as a trimmed string, or an error with
	// command name and stderr context.
	Run(name string, args ...string) (string, error)

	// RunInDir executes a command in the specified directory.
	// The directory must exist; no creation or validation is performed.
	RunInDir(dir, name string, args ...string) (string, error)
}

Runner executes external commands. Implementations must be safe for concurrent use if callers invoke methods from multiple goroutines.

Jump to

Keyboard shortcuts

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