Documentation
¶
Overview ¶
Package executil provides shell execution utilities.
Index ¶
- func RunSh(ctx context.Context, dir, cmd string) error
- type Executor
- type RealExecutor
- func (e *RealExecutor) Run(ctx context.Context, cmd string, args ...string) ([]byte, error)
- func (e *RealExecutor) RunDir(ctx context.Context, dir, cmd string, args ...string) ([]byte, error)
- func (e *RealExecutor) RunDirStream(ctx context.Context, dir string, stdout, stderr io.Writer, cmd string, ...) error
- func (e *RealExecutor) RunOutputDir(ctx context.Context, dir, cmd string, args ...string) ([]byte, []byte, error)
- func (e *RealExecutor) RunStream(ctx context.Context, stdout, stderr io.Writer, cmd string, args ...string) error
- type RecordedCommand
- type RecordingExecutor
- func (e *RecordingExecutor) Reset()
- func (e *RecordingExecutor) Run(ctx context.Context, cmd string, args ...string) ([]byte, error)
- func (e *RecordingExecutor) RunDir(ctx context.Context, dir, cmd string, args ...string) ([]byte, error)
- func (e *RecordingExecutor) RunDirStream(ctx context.Context, dir string, stdout, stderr io.Writer, cmd string, ...) error
- func (e *RecordingExecutor) RunStream(ctx context.Context, stdout, stderr io.Writer, cmd string, args ...string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RunSh ¶ added in v0.32.0
RunSh executes a shell command in the given directory (empty means inherit cwd). On failure, stderr is returned as the error message, capped at 500 bytes to prevent large or ANSI-polluted output from corrupting logs or TUI display. The original *exec.ExitError is preserved via wrapping so callers can inspect exit codes with errors.As.
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) 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) RunOutputDir ¶ added in v0.56.0
func (e *RealExecutor) RunOutputDir(ctx context.Context, dir, cmd string, args ...string) ([]byte, []byte, error)
RunOutputDir executes a command in dir (empty means inherit cwd) and returns stdout and stderr separately. Keeping the streams apart lets callers parse stdout as JSON while surfacing stderr as the error message.
type RecordedCommand ¶
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) 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.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package executiltest provides a scripted executil.Executor test double.
|
Package executiltest provides a scripted executil.Executor test double. |