executil

package
v0.31.1 Latest Latest
Warning

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

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

Documentation

Overview

Package executil provides shell execution utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	// Run executes a command and returns its combined output.
	Run(ctx context.Context, cmd string, args ...string) ([]byte, error)
	// RunDir executes a command in a specific directory.
	RunDir(ctx context.Context, dir, cmd string, args ...string) ([]byte, error)
	// RunStream executes a command and streams stdout/stderr to the provided writers.
	RunStream(ctx context.Context, stdout, stderr io.Writer, cmd string, args ...string) error
	// RunDirStream executes a command in a specific directory and streams output.
	RunDirStream(ctx context.Context, dir string, stdout, stderr io.Writer, cmd string, args ...string) error
}

Executor runs shell commands.

type RealExecutor

type RealExecutor struct{}

RealExecutor calls actual shell commands.

func (*RealExecutor) Run

func (e *RealExecutor) Run(ctx context.Context, cmd string, args ...string) ([]byte, error)

Run executes a command and returns its combined output.

func (*RealExecutor) RunDir

func (e *RealExecutor) RunDir(ctx context.Context, dir, cmd string, args ...string) ([]byte, error)

RunDir executes a command in a specific directory.

func (*RealExecutor) RunDirStream

func (e *RealExecutor) RunDirStream(ctx context.Context, dir string, stdout, stderr io.Writer, cmd string, args ...string) error

RunDirStream executes a command in a specific directory and streams output.

func (*RealExecutor) RunStream

func (e *RealExecutor) RunStream(ctx context.Context, stdout, stderr io.Writer, cmd string, args ...string) error

RunStream executes a command and streams stdout/stderr to the provided writers.

type RecordedCommand

type RecordedCommand struct {
	Dir  string
	Cmd  string
	Args []string
}

RecordedCommand captures a command that was executed.

type RecordingExecutor

type RecordingExecutor struct {
	Commands []RecordedCommand

	// Outputs maps command names to their output.
	// Key is the command name (e.g., "git").
	Outputs map[string][]byte

	// Errors maps command names to their error.
	Errors map[string]error
	// contains filtered or unexported fields
}

RecordingExecutor captures commands for testing. Configure Outputs and Errors maps to control return values.

func (*RecordingExecutor) Reset

func (e *RecordingExecutor) Reset()

Reset clears recorded commands.

func (*RecordingExecutor) Run

func (e *RecordingExecutor) Run(ctx context.Context, cmd string, args ...string) ([]byte, error)

Run records the command and returns configured output/error.

func (*RecordingExecutor) RunDir

func (e *RecordingExecutor) RunDir(ctx context.Context, dir, cmd string, args ...string) ([]byte, error)

RunDir records the command with directory and returns configured output/error.

func (*RecordingExecutor) RunDirStream

func (e *RecordingExecutor) RunDirStream(ctx context.Context, dir string, stdout, stderr io.Writer, cmd string, args ...string) error

RunDirStream records the command with directory and writes configured output to writers.

func (*RecordingExecutor) RunStream

func (e *RecordingExecutor) RunStream(ctx context.Context, stdout, stderr io.Writer, cmd string, args ...string) error

RunStream records the command and writes configured output to writers.

Jump to

Keyboard shortcuts

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