Documentation ¶
Overview ¶
Package exec contains an interface for executing commands, along with helpers TODO(bentheelder): add standardized timeout functionality & a default timeout so that commands cannot hang indefinitely (!)
Index ¶
- Variables
- func CombinedOutputLines(cmd Cmd) (lines []string, err error)
- func OutputLines(cmd Cmd) (lines []string, err error)
- func PrettyCommand(name string, args ...string) string
- func RunWithStdinWriter(cmd Cmd, writerFunc func(io.Writer) error) error
- func RunWithStdoutReader(cmd Cmd, readerFunc func(io.Reader) error) error
- type Cmd
- type Cmder
- type LocalCmd
- type LocalCmder
- type RunError
Constants ¶
This section is empty.
Variables ¶
var DefaultCmder = &LocalCmder{}
DefaultCmder is a LocalCmder instance used for convenience, packages originally using os/exec.Command can instead use pkg/kind/exec.Command which forwards to this instance TODO(bentheelder): swap this for testing TODO(bentheelder): consider not using a global for this :^)
Functions ¶
func CombinedOutputLines ¶
CombinedOutputLines is like os/exec's cmd.CombinedOutput(), but over our Cmd interface, and instead of returning the byte buffer of stderr + stdout, it scans these for lines and returns a slice of output lines
func OutputLines ¶ added in v0.6.0
OutputLines is like os/exec's cmd.Output(), but over our Cmd interface, and instead of returning the byte buffer of stdout, it scans these for lines and returns a slice of output lines
func PrettyCommand ¶ added in v0.6.0
PrettyCommand takes arguments identical to Cmder.Command, it returns a pretty printed command that could be pasted into a shell
func RunWithStdinWriter ¶ added in v0.5.0
RunWithStdinWriter runs cmd with writerFunc piped to stdin
Types ¶
type Cmd ¶
type Cmd interface { // Run executes the command (like os/exec.Cmd.Run), it should return // a *RunError if there is any error Run() error // Each entry should be of the form "key=value" SetEnv(...string) Cmd SetStdin(io.Reader) Cmd SetStdout(io.Writer) Cmd SetStderr(io.Writer) Cmd }
Cmd abstracts over running a command somewhere, this is useful for testing
func InheritOutput ¶
InheritOutput sets cmd's output to write to the current process's stdout and stderr
type LocalCmd ¶
LocalCmd wraps os/exec.Cmd, implementing the kind/pkg/exec.Cmd interface
type RunError ¶ added in v0.6.0
type RunError struct { Command []string // [Name Args...] Output []byte // Captured Stdout / Stderr of the command Inner error // Underlying error if any }
RunError represents an error running a Cmd
func RunErrorForError ¶ added in v0.6.0
RunErrorForError returns a RunError if the error contains a RunError. Otherwise it returns nil
func (*RunError) Cause ¶ added in v0.6.0
Cause mimics github.com/pkg/errors's Cause pattern for errors
func (*RunError) PrettyCommand ¶ added in v0.6.0
PrettyCommand pretty prints the command in a way that could be pasted into a shell