exec

package
v0.6.65 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: AGPL-3.0, Apache-2.0, MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalyzerOption

type AnalyzerOption func(*analyzerConfig)

AnalyzerOption is a functional option for configuring an OutputAnalyzer.

func StderrCheckForProvider

func StderrCheckForProvider(provider console.StackType) AnalyzerOption

StderrCheckForProvider returns an AnalyzerOption that enables stderr checking only for providers where stderr reliably indicates errors (e.g. Terraform), and disables it for providers that write non-error output to stderr (e.g. Ansible).

func WithStderrCheck

func WithStderrCheck(check bool) AnalyzerOption

WithStderrCheck enables or disables treating stderr output as an error.

type Error

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

func (Error) ToError

func (in Error) ToError() error

type Errors

type Errors []Error

func (Errors) ToErrors

func (in Errors) ToErrors() []error

type Executable

type Executable interface {
	ID() string
	Run(ctx context.Context) error
	Start(ctx context.Context) (WaitFn, error)
	RunWithOutput(ctx context.Context) ([]byte, error)
	RunStream(ctx context.Context, cb func([]byte)) error
	Command() string
}

func NewExecutable

func NewExecutable(command string, options ...Option) Executable

type ExecutionStrategy

type ExecutionStrategy string

ExecutionStrategy defines how executables queue should be processed.

const (
	ExecutionStrategyParallel ExecutionStrategy = "parallel"
	ExecutionStrategyOrdered  ExecutionStrategy = "ordered"
)

type Executor

type Executor interface {
	Start(ctx context.Context) error
	Add(executable Executable) error
}

func NewExecutor

func NewExecutor(errChan chan error, finishedChan chan struct{}, options ...ExecutorOption) Executor

type ExecutorOption

type ExecutorOption func(*executor)

func WithExecutionStrategy

func WithExecutionStrategy(strategy ExecutionStrategy) ExecutorOption

func WithPostRunFunc

func WithPostRunFunc(fn func(string, error)) ExecutorOption

func WithPreRunFunc

func WithPreRunFunc(fn func(string)) ExecutorOption

type Option

type Option func(*executable)

func WithArgs

func WithArgs(args []string) Option

func WithDir

func WithDir(workingDirectory string) Option

func WithEnv

func WithEnv(env []string) Option

func WithHook

func WithHook(lifecycle v1.Lifecycle, fn v1.HookFunction) Option

func WithID

func WithID(id string) Option

func WithOutputAnalyzer

func WithOutputAnalyzer(heuristics []OutputAnalyzerHeuristic, opts ...AnalyzerOption) Option

func WithOutputSinks

func WithOutputSinks(sinks ...io.WriteCloser) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type OutputAnalyzer

type OutputAnalyzer interface {
	Stdout() io.Writer
	Stderr() io.Writer

	// Detect scans the output for potential errors.
	// It uses a custom heuristics to detect issues.
	// It can result in a false positives.
	//
	// Note: Make sure that it is executed after Write
	//		 has finished to ensure proper detection.
	Detect() []error
}

OutputAnalyzer captures the command output and attempts to detect potential errors.

func NewOutputAnalyzer

func NewOutputAnalyzer(heuristics []OutputAnalyzerHeuristic, opts ...AnalyzerOption) OutputAnalyzer

type OutputAnalyzerHeuristic

type OutputAnalyzerHeuristic interface {
	Detect(input *bufio.Scanner) Errors
}

func NewKeywordDetector

func NewKeywordDetector() OutputAnalyzerHeuristic

type StdioExecutable added in v0.6.65

type StdioExecutable interface {
	Executable
	StartWithStdio(context.Context) (*StdioProcess, error)
}

StdioExecutable is implemented by executables that can be started with bidirectional standard streams. It is intentionally separate from Executable so existing callers and test doubles keep their contracts.

type StdioProcess added in v0.6.65

type StdioProcess struct {
	Stdin  io.WriteCloser
	Stdout io.ReadCloser
	Stderr io.ReadCloser
	// contains filtered or unexported fields
}

StdioProcess is a running executable with bidirectional standard input and output. The process owner must drain Stdout before calling Wait. Standard error is retained as a bounded diagnostic tail. Stop closes the input stream and terminates the process; it is safe to call more than once.

func NewStdioProcess added in v0.6.65

func NewStdioProcess(stdin io.WriteCloser, stdout, stderr io.ReadCloser, hooks StdioProcessHooks) *StdioProcess

NewStdioProcess wraps bidirectional streams and their lifecycle operations.

func StartWithStdio added in v0.6.65

func StartWithStdio(ctx context.Context, command string, options ...Option) (*StdioProcess, error)

StartWithStdio creates and starts a command with bidirectional standard streams. It is additive to NewExecutable and leaves existing execution behavior unchanged.

func (*StdioProcess) Close added in v0.6.65

func (p *StdioProcess) Close() error

Close closes all process streams. It does not wait for the process.

func (*StdioProcess) Kill added in v0.6.65

func (p *StdioProcess) Kill() error

Kill terminates the child process without waiting for it.

func (*StdioProcess) StderrTail added in v0.6.65

func (p *StdioProcess) StderrTail() string

StderrTail returns a bounded tail of the child's standard error.

func (*StdioProcess) Stop added in v0.6.65

func (p *StdioProcess) Stop() error

Stop closes stdin and terminates the child process.

func (*StdioProcess) Wait added in v0.6.65

func (p *StdioProcess) Wait() error

Wait waits for the process and runs its post-start lifecycle hook. It also closes the process streams after the child exits.

type StdioProcessHooks added in v0.6.65

type StdioProcessHooks struct {
	Wait       func() error
	Kill       func() error
	Stop       func() error
	Close      func() error
	StderrTail func() string
}

StdioProcessHooks supplies lifecycle operations for a StdioProcess. It is useful for protocol adapters and deterministic tests that provide their own in-memory streams.

type WaitFn

type WaitFn func() error

Jump to

Keyboard shortcuts

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