cmd

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithShellExecutor

func WithShellExecutor(ctx context.Context, executor ShellExecutor) context.Context

WithShellExecutor returns a context with the given shell executor

Types

type DefaultShellExecutor

type DefaultShellExecutor struct{}

DefaultShellExecutor implements ShellExecutor using os/exec

func (*DefaultShellExecutor) Exec

func (e *DefaultShellExecutor) Exec(ctx context.Context, command string, args ...string) ([]byte, error)

Exec executes a command using os/exec.CommandContext

type MockCall

type MockCall struct {
	Command string
	Args    []string
}

MockCall represents a recorded command execution for testing

type MockShellExecutor

type MockShellExecutor struct {
	// contains filtered or unexported fields
}

MockShellExecutor is a mock implementation of ShellExecutor for testing

func NewMockShellExecutor

func NewMockShellExecutor() *MockShellExecutor

NewMockShellExecutor creates a new mock shell executor

func (*MockShellExecutor) AddCommandString

func (m *MockShellExecutor) AddCommandString(command string, args []string, output string, err error)

AddCommandString mocks a command with specific arguments and a string output

func (*MockShellExecutor) AddPartialMatcherString

func (m *MockShellExecutor) AddPartialMatcherString(command string, args []string, output string, err error)

AddPartialMatcherString mocks a command with partial argument matching

func (*MockShellExecutor) Exec

func (m *MockShellExecutor) Exec(ctx context.Context, command string, args ...string) ([]byte, error)

Exec records the call and returns a mocked output or error

func (*MockShellExecutor) GetCallLog

func (m *MockShellExecutor) GetCallLog() []MockCall

GetCallLog returns the history of commands executed

type ShellExecutor

type ShellExecutor interface {
	Exec(ctx context.Context, command string, args ...string) (output []byte, err error)
}

ShellExecutor defines the interface for executing shell commands

func GetShellExecutor

func GetShellExecutor(ctx context.Context) ShellExecutor

GetShellExecutor retrieves the shell executor from context, or returns default

Jump to

Keyboard shortcuts

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