Documentation ¶
Index ¶
- func Available(commands ...string) (ok bool)
- func Execute(cmd string, args ...string) error
- func GetGlobalVerbose() bool
- func SetGlobalVerbose(to bool)
- type Command
- func (c *Command) Add(cmd string, args ...string) Commands
- func (c *Command) AddErrorWriter(writer io.Writer) *Command
- func (c *Command) AddOutputWriter(writer io.Writer) *Command
- func (c *Command) AddWriter(writer io.Writer) *Command
- func (c *Command) Env(env ...string) *Command
- func (c *Command) Filter(regex, replaceAll string) (*Command, error)
- func (c *Command) Pipe(cmd string, args ...string) *Command
- func (c *Command) Run() (res *Status, err error)
- func (c *Command) RunSilent() (res *Status, err error)
- func (c *Command) RunSilentSuccess() error
- func (c *Command) RunSilentSuccessOutput() (output *Stream, err error)
- func (c *Command) RunSuccess() error
- func (c *Command) RunSuccessOutput() (output *Stream, err error)
- func (c *Command) String() string
- func (c *Command) Verbose() *Command
- type Commands
- type Status
- type Stream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Available ¶
Available verifies that the specified `commands` are available within the current `$PATH` environment and returns true if so. The function does not check for duplicates nor if the provided slice is empty.
func Execute ¶
Execute is a convenience function which creates a new Command, executes it and evaluates its status.
func GetGlobalVerbose ¶
func GetGlobalVerbose() bool
GetGlobalVerbose returns the globally set command verbosity.
func SetGlobalVerbose ¶
func SetGlobalVerbose(to bool)
SetGlobalVerbose sets the global command verbosity to the specified value.
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
A generic command abstraction.
func NewWithWorkDir ¶
NewWithWorkDir creates a new command from the provided workDir and the command arguments.
func (*Command) Add ¶
Add a command with the same working directory as well as verbosity mode. Returns a new Commands instance.
func (*Command) AddErrorWriter ¶
AddErrorWriter can be used to add an additional error (stderr) writer to the command, for example when having the need to log to files.
func (*Command) AddOutputWriter ¶
AddOutputWriter can be used to add an additional output (stdout) writer to the command, for example when having the need to log to files.
func (*Command) AddWriter ¶
AddWriter can be used to add an additional output (stdout) and error (stderr) writer to the command, for example when having the need to log to files.
func (*Command) Env ¶
Env specifies the environment added to the command. Each entry is of the form "key=value". The environment of the current process is being preserved, while it is possible to overwrite already existing environment variables.
func (*Command) Filter ¶ added in v0.3.0
Filter adds an output filter regular expression to the command. Every output will then be replaced with the string provided by replaceAll.
func (*Command) Run ¶
Run starts the command and waits for it to finish. It returns an error if the command execution was not possible at all, otherwise the Status. This method prints the commands output during execution.
func (*Command) RunSilent ¶
Run starts the command and waits for it to finish. It returns an error if the command execution was not possible at all, otherwise the Status. This method does not print the output of the command during its execution.
func (*Command) RunSilentSuccess ¶
RunSilentSuccess starts the command and waits for it to finish. It returns an error if the command execution was not successful. This method does not print the output of the command during its execution.
func (*Command) RunSilentSuccessOutput ¶
RunSilentSuccessOutput starts the command and waits for it to finish. It returns an error if the command execution was not successful, otherwise its output. This method does not print the output of the command during its execution.
func (*Command) RunSuccess ¶
RunSuccess starts the command and waits for it to finish. It returns an error if the command execution was not successful.
func (*Command) RunSuccessOutput ¶
RunSuccessOutput starts the command and waits for it to finish. It returns an error if the command execution was not successful, otherwise its output.
type Commands ¶
type Commands []*Command
Commands is an abstraction over multiple Command structures.
type Status ¶
type Status struct { *Stream // contains filtered or unexported fields }
A generic command exit status.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream combines standard output and error.
func (*Stream) OutputTrimNL ¶
OutputTrimNL returns stdout of the command status with newlines trimmed Use only when output is expected to be a single "word", like a version string.