Documentation ¶
Overview ¶
Package exec provides an injectable interface and implementations for running commands.
Index ¶
- Variables
- type Cmd
- type CodeExitError
- type ExitError
- type ExitErrorWrapper
- type FakeCmd
- func (fake *FakeCmd) CombinedOutput() ([]byte, error)
- func (fake *FakeCmd) Output() ([]byte, error)
- func (fake *FakeCmd) Run() error
- func (fake *FakeCmd) SetDir(dir string)
- func (fake *FakeCmd) SetStderr(out io.Writer)
- func (fake *FakeCmd) SetStdin(in io.Reader)
- func (fake *FakeCmd) SetStdout(out io.Writer)
- func (fake *FakeCmd) Stop()
- type FakeCombinedOutputAction
- type FakeCommandAction
- type FakeExec
- type FakeExitError
- type FakeRunAction
- type Interface
Constants ¶
This section is empty.
Variables ¶
var ErrExecutableNotFound = osexec.ErrNotFound
ErrExecutableNotFound is returned if the executable is not found.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd interface { // Run runs the command to the completion. Run() error // CombinedOutput runs the command and returns its combined standard output // and standard error. This follows the pattern of package os/exec. CombinedOutput() ([]byte, error) // Output runs the command and returns standard output, but not standard err Output() ([]byte, error) SetDir(dir string) SetStdin(in io.Reader) SetStdout(out io.Writer) SetStderr(out io.Writer) // Stops the command by sending SIGTERM. It is not guaranteed the // process will stop before this function returns. If the process is not // responding, an internal timer function will send a SIGKILL to force // terminate after 10 seconds. Stop() }
Cmd is an interface that presents an API that is very similar to Cmd from os/exec. As more functionality is needed, this can grow. Since Cmd is a struct, we will have to replace fields with get/set method pairs.
type CodeExitError ¶ added in v1.4.1
CodeExitError is an implementation of ExitError consisting of an error object and an exit code (the upper bits of os.exec.ExitStatus).
func (CodeExitError) Error ¶ added in v1.4.1
func (e CodeExitError) Error() string
func (CodeExitError) ExitStatus ¶ added in v1.4.1
func (e CodeExitError) ExitStatus() int
func (CodeExitError) Exited ¶ added in v1.4.1
func (e CodeExitError) Exited() bool
func (CodeExitError) String ¶ added in v1.4.1
func (e CodeExitError) String() string
type ExitError ¶
ExitError is an interface that presents an API similar to os.ProcessState, which is what ExitError from os/exec is. This is designed to make testing a bit easier and probably loses some of the cross-platform properties of the underlying library.
type ExitErrorWrapper ¶ added in v1.4.1
ExitErrorWrapper is an implementation of ExitError in terms of os/exec ExitError. Note: standard exec.ExitError is type *os.ProcessState, which already implements Exited().
func (ExitErrorWrapper) ExitStatus ¶ added in v1.4.1
func (eew ExitErrorWrapper) ExitStatus() int
ExitStatus is part of the ExitError interface.
type FakeCmd ¶ added in v0.5.1
type FakeCmd struct { Argv []string CombinedOutputScript []FakeCombinedOutputAction CombinedOutputCalls int CombinedOutputLog [][]string RunScript []FakeRunAction RunCalls int RunLog [][]string Dirs []string Stdin io.Reader Stdout io.Writer Stderr io.Writer }
A simple scripted Cmd type.
func (*FakeCmd) CombinedOutput ¶ added in v0.5.1
type FakeCombinedOutputAction ¶ added in v0.5.1
type FakeCommandAction ¶ added in v0.5.1
type FakeExec ¶ added in v0.5.1
type FakeExec struct { CommandScript []FakeCommandAction CommandCalls int LookPathFunc func(string) (string, error) }
A simple scripted Interface type.
type FakeExitError ¶ added in v0.5.1
type FakeExitError struct {
Status int
}
A simple fake ExitError type.
func (*FakeExitError) Error ¶ added in v0.5.1
func (fake *FakeExitError) Error() string
func (*FakeExitError) ExitStatus ¶ added in v0.5.1
func (fake *FakeExitError) ExitStatus() int
func (*FakeExitError) Exited ¶ added in v0.5.1
func (fake *FakeExitError) Exited() bool
func (*FakeExitError) String ¶ added in v0.5.1
func (fake *FakeExitError) String() string
type FakeRunAction ¶ added in v1.7.0
type Interface ¶
type Interface interface { // Command returns a Cmd instance which can be used to run a single command. // This follows the pattern of package os/exec. Command(cmd string, args ...string) Cmd // LookPath wraps os/exec.LookPath LookPath(file string) (string, error) }
Interface is an interface that presents a subset of the os/exec API. Use this when you want to inject fakeable/mockable exec behavior.