Documentation ¶
Overview ¶
Package run is a package with utilities for running command and handling results.
Index ¶
- Variables
- func Quiet(ctx context.Context, name string, args ...string) error
- type CommandSet
- type CommandSpec
- type Result
- type Runner
- func (r Runner) Quiet(ctx context.Context, name string, args ...string) error
- func (r Runner) WithCombinedOutput(ctx context.Context, name string, args ...string) *Result
- func (r Runner) WithOutput(ctx context.Context, name string, args ...string) *Result
- func (r Runner) WithOutputTimeout(ctx context.Context, timeout time.Duration, name string, args ...string) *Result
- type RunnerInterface
Constants ¶
This section is empty.
Variables ¶
var ( // Client is the Runner running commands. Client RunnerInterface // ErrCommandTemplate is the error returned when a CommandSpec's Command template is boggus. ErrCommandTemplate = errors.New("invalid command format template") // ErrTemplateError is the error returned when a CommandSpec's Error template is boggus. ErrTemplateError = errors.New("invalid error format template") )
Functions ¶
Types ¶
type CommandSet ¶
type CommandSet []CommandSpec
CommandSet is set of commands to be executed together, IOW a command batch.
type CommandSpec ¶
type CommandSpec struct { // Command is the command template i.e: "echo '{{.MyDataString}}'". Command string // Error is the error template, if the command fails this template is // used to build the error message, i.e: "failed to parse file {{.FileName}}". Error string }
CommandSpec defines a Command template and an Error template. The data structure to be used with the templates is up to the user to define.
type Result ¶
type Result struct { // Exit code. Set to -1 if we failed to run the command. ExitCode int // Stderr or err.Error if we failed to run the command. StdErr string // Stdout or "" if we failed to run the command. StdOut string // Combined is the process' stdout and stderr combined. Combined string }
Result wraps a command execution result.
func WithCombinedOutput ¶
WithCombinedOutput runs the current RunCLient's WithCombinedOutput function.
func WithOutput ¶
WithOutput runs the current RunClient's WithOutput() function.
type Runner ¶
type Runner struct{}
Runner implements the RunnerInterface and represents the runner running commands.
func (Runner) Quiet ¶
Quiet runs a command and doesn't return a result, but an error in case of failure.
func (Runner) WithCombinedOutput ¶
WithCombinedOutput returns a result with stderr and stdout combined in the Combined member of Result.
func (Runner) WithOutput ¶
WithOutput runs a command and returns the result.
type RunnerInterface ¶
type RunnerInterface interface { // Quiet runs a command and doesn't return a result, but errors in case of failure. Quiet(ctx context.Context, name string, args ...string) error // WithOutput runs a command and returns the result. WithOutput(ctx context.Context, name string, args ...string) *Result // WithOutputTimeout runs a command with a defined timeout and returns its result. WithOutputTimeout(ctx context.Context, timeout time.Duration, name string, args ...string) *Result // WithCombinedOutput runs a command and returns a result with stderr and stdout // combined in the Combined member of Result. WithCombinedOutput(ctx context.Context, name string, args ...string) *Result }
RunnerInterface defines the runner running commands.