Documentation ¶
Index ¶
- Variables
- type Cmd
- func (c *Cmd) Directory(dir string) *Cmd
- func (c *Cmd) Env(env []string) *Cmd
- func (c *Cmd) ExpectSuccess() *Cmd
- func (c *Cmd) LogFn(fn PrintfFn) *Cmd
- func (c *Cmd) LogPrefix(prefix string) *Cmd
- func (c *Cmd) Run(ctx context.Context) (*Result, error)
- func (c *Cmd) RunCombinedOut(ctx context.Context) (*ResultOut, error)
- func (c *Cmd) Stderr(w io.Writer) *Cmd
- func (c *Cmd) Stdout(w io.Writer) *Cmd
- type ExitCodeError
- type PrintfFn
- type Result
- type ResultOut
- type SprintFn
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultLogFn is the default debug print function. DefaultLogFn PrintfFn // DefaultLogPrefix is the default prefix that is prepended to messages passed to the debugf function. DefaultLogPrefix = "exec: " // DefaultStderrColorFn is the default function that is used to colorize stderr output that is streamed to the log function. DefaultStderrColorFn = color.New(color.FgRed).SprintFunc() )
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd struct {
// contains filtered or unexported fields
}
Cmd represent a command that can be executed as new process.
func (*Cmd) ExpectSuccess ¶
ExpectSuccess when the command is executed and the execution of the process fails (e.g. exit status != 0 on unix) return an ExitCodeError instead of nil.
func (*Cmd) LogPrefix ¶
LogPrefix defines a string that is used as prefix for all messages written via *Cmd.LogFn.
func (*Cmd) Run ¶
Run executes the command. If the command could not be started an error is returned. If the command was started successfully, and terminated unsuccessfully no error is returned, except if *Cmd.ExpectSuccess() was called before.
func (*Cmd) RunCombinedOut ¶
RunCombinedOut executes the command and stores the combined stdout and stderr output of the process in ResultOut.CombinedOutput.
type ExitCodeError ¶
type ExitCodeError struct {
*Result
}
ExitCodeError is returned from Run() when a command exited with a code != 0.
func (*ExitCodeError) ColoredError ¶
func (e *ExitCodeError) ColoredError(highlightFn SprintFn, errorFn SprintFn, withCmdOutput bool) string
func (*ExitCodeError) Error ¶
func (e *ExitCodeError) Error() string
Error returns the error description.
type Result ¶
type Result struct { Command string Dir string ExitCode int // contains filtered or unexported fields }
Result describes the result of a run Cmd.
func (*Result) ExpectSuccess ¶
ExpectSuccess the command did not execute successful (e.g. exit code != 0 on unix), a ExitCodeError is returned.