executor

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsCommandNotFound

func IsCommandNotFound(err error) bool

IsCommandNotFound checks if an error is a CommandNotFoundError.

Types

type CommandNotFoundError

type CommandNotFoundError struct {
	Command string
}

CommandNotFoundError is returned when a command doesn't exist in PATH.

func (*CommandNotFoundError) Error

func (e *CommandNotFoundError) Error() string

type Executor

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

Executor runs shell commands using mvdan/sh interpreter.

func New

func New() *Executor

New creates a new Executor.

func (*Executor) Environ

func (e *Executor) Environ() []string

Environ returns all environment variables in "NAME=value" format. This is used for tab-completion of environment variables.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, command string, stdout, stderr io.Writer) (*Result, error)

Execute runs a command using the mvdan/sh interpreter.

func (*Executor) Functions

func (e *Executor) Functions() []string

Functions returns the names of all tracked user-defined functions. This is used for tab-completion of aliases and functions.

func (*Executor) GetRunner

func (e *Executor) GetRunner() *interp.Runner

GetRunner returns the underlying interpreter runner (for testing).

func (*Executor) Reset

func (e *Executor) Reset()

Reset clears the interpreter state, including all function definitions. The runner will be recreated on the next Execute() call.

func (*Executor) SetCaptureLimit

func (e *Executor) SetCaptureLimit(limit int64)

SetCaptureLimit sets the maximum number of bytes to capture. Use a negative value for unlimited capture, or 0 to disable capture.

func (*Executor) SetExportedEnv

func (e *Executor) SetExportedEnv(name, value string)

SetExportedEnv sets an exported environment variable for the shell session.

func (*Executor) SetPositionalArgs

func (e *Executor) SetPositionalArgs(args []string)

SetPositionalArgs sets $0, $1, $2, etc. for script execution. These are used when creating the interpreter for -c command execution.

func (*Executor) SetProgressEnabled

func (e *Executor) SetProgressEnabled(enabled bool)

SetProgressEnabled enables or disables progress bar.

func (*Executor) SetProgressThreshold

func (e *Executor) SetProgressThreshold(d time.Duration)

SetProgressThreshold sets how long to wait before showing progress.

func (*Executor) SetShellName

func (e *Executor) SetShellName(name string)

SetShellName sets the shell name for $0.

func (*Executor) ShellName

func (e *Executor) ShellName() string

ShellName returns the shell name.

func (*Executor) ShellPath

func (e *Executor) ShellPath() string

ShellPath returns the path to the shell executable.

func (*Executor) SyncRunnerDir

func (e *Executor) SyncRunnerDir()

SyncRunnerDir syncs the persistent runner's working directory with the process. Call this after changing directory via os.Chdir() (e.g., after builtin cd).

type Result

type Result struct {
	ExitCode       int
	Duration       time.Duration
	Command        string
	CapturedOutput string
	UsedPTY        bool // True if command ran with PTY (TUI apps, interactive programs)
}

Result contains the outcome of a command execution.

Jump to

Keyboard shortcuts

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