exec

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: May 24, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package exec provides abstractions for command execution. This package enables testable code by allowing CLI commands to be mocked.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandExecutor

type CommandExecutor interface {
	// Execute runs a command with the given context and arguments.
	// Returns stdout, stderr, and any error that occurred.
	Execute(ctx context.Context, name string, args ...string) (stdout []byte, stderr []byte, err error)
}

CommandExecutor defines an interface for executing shell commands. This abstraction allows for mocking CLI tool behavior in tests.

func DefaultExecutor

func DefaultExecutor() CommandExecutor

DefaultExecutor returns the standard production executor. This is used as the default when no executor is injected.

type EnvCommandExecutor added in v0.2.6

type EnvCommandExecutor interface {
	CommandExecutor
	ExecuteWithEnv(ctx context.Context, env []string, name string, args ...string) (stdout []byte, stderr []byte, err error)
}

EnvCommandExecutor extends CommandExecutor with per-call environment variable injection. Implementations append the supplied entries to the caller's existing environment (os.Environ) before spawning the child. Each entry is a "KEY=VALUE" string, matching exec.Cmd.Env semantics. When env is empty or nil the call is equivalent to Execute (no env mutation on the child).

type RealCommandExecutor

type RealCommandExecutor struct{}

RealCommandExecutor executes actual shell commands using os/exec. This is the production implementation.

func (*RealCommandExecutor) Execute

func (r *RealCommandExecutor) Execute(ctx context.Context, name string, args ...string) ([]byte, []byte, error)

Execute runs an actual shell command.

func (*RealCommandExecutor) ExecuteWithEnv added in v0.2.6

func (r *RealCommandExecutor) ExecuteWithEnv(ctx context.Context, env []string, name string, args ...string) ([]byte, []byte, error)

ExecuteWithEnv runs a shell command with additional environment variables appended to the parent process's environment. Entries later in env override earlier ones, including any matching keys from os.Environ().

Jump to

Keyboard shortcuts

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