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 Output(cmd Cmd) ([]byte, 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 CommandContext ¶ added in v0.8.0
CommandContext is a convenience wrapper over DefaultCmder.CommandContext
func InheritOutput ¶
InheritOutput sets cmd's output to write to the current process's stdout and stderr
type Cmder ¶
type Cmder interface { // command, args..., just like os/exec.Cmd Command(string, ...string) Cmd CommandContext(context.Context, string, ...string) Cmd }
Cmder abstracts over creating commands
type LocalCmd ¶
LocalCmd wraps os/exec.Cmd, implementing the kind/pkg/exec.Cmd interface
type LocalCmder ¶
type LocalCmder struct{}
LocalCmder is a factory for LocalCmd, implementing Cmder
func (*LocalCmder) Command ¶
func (c *LocalCmder) Command(name string, arg ...string) Cmd
Command returns a new exec.Cmd backed by Cmd
func (*LocalCmder) CommandContext ¶ added in v0.8.0
CommandContext is like Command but includes a context
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