exec

package
v0.6.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandExecutor

type CommandExecutor interface {
	// LookPath searches for an executable named file in the directories
	// named by the PATH environment variable.
	LookPath(file string) (string, error)

	// Execute runs the command with the given name and arguments.
	// It waits for the command to complete and returns any error.
	Execute(name string, arg ...string) error
}

CommandExecutor defines an interface for running external commands. This abstraction allows for easier testing by providing a mockable interface.

type ExecError

type ExecError struct {
	Err    error
	Output string
}

ExecError wraps an execution error with the command output

func (*ExecError) Error

func (e *ExecError) Error() string

type MockCommandExecutor

type MockCommandExecutor struct {
	// Commands records all commands that were executed
	Commands []string

	// LookPathFunc allows custom behavior for LookPath in tests
	LookPathFunc func(file string) (string, error)

	// ExecuteFunc allows custom behavior for Execute in tests
	ExecuteFunc func(name string, arg ...string) error
}

MockCommandExecutor is a mock implementation of CommandExecutor for testing. It records all commands that would be executed without actually running them.

func (*MockCommandExecutor) Execute

func (m *MockCommandExecutor) Execute(name string, arg ...string) error

Execute implements the CommandExecutor interface for testing. It records the command that would be executed.

func (*MockCommandExecutor) LookPath

func (m *MockCommandExecutor) LookPath(file string) (string, error)

LookPath implements the CommandExecutor interface for testing.

type RealCommandExecutor

type RealCommandExecutor struct{}

RealCommandExecutor implements CommandExecutor using the actual os/exec package. This is the production implementation that executes real system commands.

func (*RealCommandExecutor) Execute

func (e *RealCommandExecutor) Execute(name string, arg ...string) error

Execute runs the command with the given name and arguments. It waits for the command to complete and returns any error.

func (*RealCommandExecutor) LookPath

func (e *RealCommandExecutor) LookPath(file string) (string, error)

LookPath searches for an executable named file in the directories named by the PATH environment variable.

Jump to

Keyboard shortcuts

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