Documentation ¶
Overview ¶
Package shellz provides various utilities for running commands.
Index ¶
- func RestoreDefaultExecutor()
- type Command
- func (c *Command) AddParams(params ...string) *Command
- func (c *Command) AddParamsIfTrue(cond bool, params ...string) *Command
- func (c *Command) CombinedOutput() ([]byte, error)
- func (c *Command) CombinedOutputString() (string, error)
- func (c *Command) Exec() error
- func (c *Command) GetDir() string
- func (c *Command) GetEcho() *bool
- func (c *Command) GetEnv() map[string]string
- func (c *Command) GetIn() io.Reader
- func (c *Command) GetParams() []string
- func (c *Command) Lines(lineFunc func(string)) error
- func (c *Command) MergeEnv(env map[string]string) *Command
- func (c *Command) MustCombinedOutput() []byte
- func (c *Command) MustCombinedOutputString() string
- func (c *Command) MustExec()
- func (c *Command) MustLines(lineFunc func(string))
- func (c *Command) MustOutput(echoStderr bool) []byte
- func (c *Command) MustOutputString(echoStderr bool) string
- func (c *Command) MustRun()
- func (c *Command) Output(echoStderr bool) ([]byte, error)
- func (c *Command) OutputString(echoStderr bool) (string, error)
- func (c *Command) Run() error
- func (c *Command) SetDir(dir string) *Command
- func (c *Command) SetEcho(echo bool) *Command
- func (c *Command) SetEnv(k, v string) *Command
- func (c *Command) SetExecutor(executor Executor) *Command
- func (c *Command) SetIn(in io.Reader) *Command
- type ExecutionError
- func (e *ExecutionError) Error() string
- func (e *ExecutionError) GetCapturedStderr() string
- func (e *ExecutionError) GetCommand() string
- func (e *ExecutionError) GetDir() string
- func (e *ExecutionError) GetEnv() map[string]string
- func (e *ExecutionError) GetExitCode() int
- func (e *ExecutionError) GetParams() []string
- func (e *ExecutionError) Unwrap() error
- type Executor
- type RealExecutor
- func (e *RealExecutor) ExecCmdCombinedOutput(_ *Command, cmd *exec.Cmd) ([]byte, error)
- func (e *RealExecutor) ExecCmdOutput(_ *Command, cmd *exec.Cmd) ([]byte, error)
- func (e *RealExecutor) ExecCmdRun(_ *Command, cmd *exec.Cmd) error
- func (e *RealExecutor) ExecCmdStart(_ *Command, cmd *exec.Cmd) error
- func (e *RealExecutor) ExecCmdWait(_ *Command, cmd *exec.Cmd) error
- func (e *RealExecutor) ExecLookPath(_ *Command, file string) (string, error)
- func (e *RealExecutor) OSChdir(_ *Command, dir string) error
- func (e *RealExecutor) SyscallExec(_ *Command, argv0 string, argv []string, envv []string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RestoreDefaultExecutor ¶
func RestoreDefaultExecutor()
RestoreDefaultExecutor restores the default value of DefaultExecutor.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command describes a command.
func NewCommand ¶
NewCommand creates a new *Command.
func (*Command) AddParamsIfTrue ¶
AddParamsIfTrue adds the given params if the condition is true.
func (*Command) CombinedOutput ¶
CombinedOutput runs the command and returns a buffer containing the resulting combined standard output and error.
func (*Command) CombinedOutputString ¶
CombinedOutputString is like *Command.CombinedOutput but returns a string.
func (*Command) MustCombinedOutput ¶
MustCombinedOutput is like *Command.CombinedOutput but panics on error.
func (*Command) MustCombinedOutputString ¶
MustCombinedOutputString is like *Command.CombinedOutputString but panics on error.
func (*Command) MustExec ¶
func (c *Command) MustExec()
MustExec is like *Command.Exec but panics on error.
func (*Command) MustLines ¶
MustLines is like *Command.Lines but panics on error.
func (*Command) MustOutput ¶
MustOutput is like *Command.Output but panics on error.
func (*Command) MustOutputString ¶
MustOutputString is like *Command.OutputString but panics on error.
func (*Command) MustRun ¶
func (c *Command) MustRun()
MustRun is like *Command.Run but panics on error.
func (*Command) Output ¶
Output runs the command and returns a buffer containing the resulting standard output. Standard error is not redirected.
func (*Command) OutputString ¶
OutputString is like *Command.Output but returns a string.
func (*Command) SetExecutor ¶
SetExecutor sets the Executor for the command.
type ExecutionError ¶
type ExecutionError struct {
// contains filtered or unexported fields
}
ExecutionError describes an error.
func NewExecutionError ¶
func NewExecutionError(err error, c *Command) *ExecutionError
NewExecutionError initializes a new *ExecutionError.
func (*ExecutionError) Error ¶
func (e *ExecutionError) Error() string
Error implements the error interface.
func (*ExecutionError) GetCapturedStderr ¶
func (e *ExecutionError) GetCapturedStderr() string
GetCapturedStderr returns the originating captured standard error (if available).
func (*ExecutionError) GetCommand ¶
func (e *ExecutionError) GetCommand() string
GetCommand returns the originating command.
func (*ExecutionError) GetDir ¶
func (e *ExecutionError) GetDir() string
GetDir returns the originating dir.
func (*ExecutionError) GetEnv ¶
func (e *ExecutionError) GetEnv() map[string]string
GetEnv returns the originating env.
func (*ExecutionError) GetExitCode ¶
func (e *ExecutionError) GetExitCode() int
GetExitCode returns the originating exit code.
func (*ExecutionError) GetParams ¶
func (e *ExecutionError) GetParams() []string
GetParams returns the originating params.
func (*ExecutionError) Unwrap ¶
func (e *ExecutionError) Unwrap() error
Unwrap implements the errorz.UnwrapSingle interface.
type Executor ¶
type Executor interface { ExecCmdCombinedOutput(c *Command, cmd *exec.Cmd) ([]byte, error) ExecCmdOutput(c *Command, cmd *exec.Cmd) ([]byte, error) ExecCmdRun(c *Command, cmd *exec.Cmd) error ExecCmdStart(c *Command, cmd *exec.Cmd) error ExecCmdWait(c *Command, cmd *exec.Cmd) error ExecLookPath(c *Command, file string) (string, error) OSChdir(c *Command, dir string) error SyscallExec(c *Command, argv0 string, argv []string, envv []string) error }
Executor implements the OS-level operations related to a command.
type RealExecutor ¶
type RealExecutor struct { }
RealExecutor implements the Executor interface and actually runs commands on the host.
func (*RealExecutor) ExecCmdCombinedOutput ¶
ExecCmdCombinedOutput implements the Executor interface.
func (*RealExecutor) ExecCmdOutput ¶
ExecCmdOutput implements the Executor interface.
func (*RealExecutor) ExecCmdRun ¶
func (e *RealExecutor) ExecCmdRun(_ *Command, cmd *exec.Cmd) error
ExecCmdRun implements the Executor interface.
func (*RealExecutor) ExecCmdStart ¶
func (e *RealExecutor) ExecCmdStart(_ *Command, cmd *exec.Cmd) error
ExecCmdStart implements the Executor interface.
func (*RealExecutor) ExecCmdWait ¶
func (e *RealExecutor) ExecCmdWait(_ *Command, cmd *exec.Cmd) error
ExecCmdWait implements the Executor interface.
func (*RealExecutor) ExecLookPath ¶
func (e *RealExecutor) ExecLookPath(_ *Command, file string) (string, error)
ExecLookPath implements the Executor interface.
func (*RealExecutor) OSChdir ¶
func (e *RealExecutor) OSChdir(_ *Command, dir string) error
OSChdir implements the Executor interface.
func (*RealExecutor) SyscallExec ¶
SyscallExec implements the Executor interface.