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).
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.
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.