cmdrunner

package
v1.14.2 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2025 License: Apache-2.0 Imports: 10 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redact

func Redact(redactions []string, runOutput string) string

Types

type CaptureOutputMode

type CaptureOutputMode int
const (
	CaptureOutputModeCombined CaptureOutputMode = iota
	CaptureOutputModeStdout
)

type CmdRunner

type CmdRunner interface {

	// Run runs a command, given runOptions
	Run(runOptions *RunOptions, format string, vars ...interface{}) (RunResult, error)

	// RunWithPositionalAndNamedArguments runs a command, given runOptions, positional and named arguments
	RunWithPositionalAndNamedArguments(runOptions *RunOptions,
		positionalArgs []string,
		namedArgs map[string]string) (RunResult, error)

	// Stream streams command output
	Stream(ctx context.Context, runOptions *RunOptions, format string, vars ...interface{}) (io.ReadCloser, error)
}

CmdRunner specifies the interface to an underlying command runner

type MockRunner

type MockRunner struct {
	mock.Mock
}

func NewMockRunner

func NewMockRunner() *MockRunner

func (*MockRunner) Run

func (m *MockRunner) Run(runOptions *RunOptions, format string, vars ...interface{}) (RunResult, error)

func (*MockRunner) RunWithPositionalAndNamedArguments

func (m *MockRunner) RunWithPositionalAndNamedArguments(runOptions *RunOptions,
	positionalArgs []string,
	namedArgs map[string]string) (RunResult, error)

func (*MockRunner) Stream

func (m *MockRunner) Stream(ctx context.Context,
	runOptions *RunOptions,
	format string,
	vars ...interface{}) (io.ReadCloser, error)

type RunOptions

type RunOptions struct {
	WorkingDir        *string
	Stdin             *string
	Env               map[string]string
	LogRedactions     []string
	CaptureOutputMode CaptureOutputMode

	// will log if command executed successfully
	LogOnlyOnFailure bool

	// skip logging when command execution fails
	SkipLogOnFailure bool
}

RunOptions specifies runOptions to CmdRunner.Run

type RunResult

type RunResult struct {
	Output   string
	Stderr   string
	ExitCode int
}

RunResult holds command execution returned values

type ShellRunner

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

func NewShellRunner

func NewShellRunner(parentLogger logger.Logger) (*ShellRunner, error)

func (*ShellRunner) Run

func (sr *ShellRunner) Run(runOptions *RunOptions, format string, vars ...interface{}) (RunResult, error)

func (*ShellRunner) RunWithPositionalAndNamedArguments

func (sr *ShellRunner) RunWithPositionalAndNamedArguments(runOptions *RunOptions,
	positionalArgs []string,
	namedArgs map[string]string) (RunResult, error)

func (*ShellRunner) SetShell

func (sr *ShellRunner) SetShell(shell string)

func (*ShellRunner) Stream

func (sr *ShellRunner) Stream(ctx context.Context,
	runOptions *RunOptions,
	format string,
	vars ...interface{}) (io.ReadCloser, error)

Jump to

Keyboard shortcuts

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