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 InheritOutput(cmd Cmd)
- func NoOutput(cmd Cmd)
- func Output(cmd Cmd) ([]byte, error)
- func OutputLines(cmd Cmd) (lines []string, err error)
- func SetOutput(cmd Cmd, stdoutWriter, stderrWriter io.Writer)
- type Cmd
- type Cmder
- type LocalCmd
- type LocalCmder
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 InheritOutput ¶
func InheritOutput(cmd Cmd)
InheritOutput sets cmd's output to write to the current process's stdout and stderr
func OutputLines ¶
OutputLines is like os/exec's cmd.Output(), but over our Cmd interface, and instead of returning the byte buffer of stdout, it scans it for lines and returns a slice of output lines
Types ¶
type Cmd ¶
type Cmd interface { 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 SetDir(string) Cmd }
Cmd abstracts over running a command somewhere, this is useful for testing
func RawCommand ¶
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 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 ¶
CommandContext returns a new exec.Cmd with the context, backed by Cmd