Documentation ¶
Overview ¶
Utilities that make executing commands on the local system a little bit easier.
Index ¶
- func Env(name string, fallback ...interface{}) string
- func EnvBool(name string, fallback ...interface{}) bool
- func EnvDuration(name string, fallback ...interface{}) time.Duration
- func EnvFloat(name string, fallback ...interface{}) float64
- func EnvInt(name string, fallback ...interface{}) int64
- func EnvTime(name string, fallback ...interface{}) time.Time
- func FindShell() string
- func IsRoot() bool
- func Join(in interface{}) string
- func RootOr(ifRoot interface{}, notRoot interface{}) interface{}
- func RootOrString(ifRoot interface{}, notRoot interface{}) string
- func TrapSignals(after func(sig os.Signal) bool, signals ...os.Signal)
- func Which(cmdname string, path ...string) string
- func WhichAll(cmdname string, path ...string) []string
- type Cmd
- func (self *Cmd) CombinedOutput() ([]byte, error)
- func (self *Cmd) Kill() error
- func (self *Cmd) Output() ([]byte, error)
- func (self *Cmd) Run() error
- func (self *Cmd) SetEnv(key string, value interface{})
- func (self *Cmd) Start() error
- func (self *Cmd) Status() Status
- func (self *Cmd) WaitStatus() Status
- type CommandStatusFunc
- type OutputLineFunc
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnvDuration ¶ added in v1.7.36
func FindShell ¶ added in v1.7.30
func FindShell() string
Uses environment variables and other configurations to attempt to locate the path to the user's shell.
func Join ¶ added in v1.7.24
func Join(in interface{}) string
Take an *exec.Cmd or []string and return a shell-executable command line string.
func RootOr ¶ added in v1.7.31
func RootOr(ifRoot interface{}, notRoot interface{}) interface{}
Returns the first argument if the current user is root, and the second if not.
func RootOrString ¶ added in v1.7.31
func RootOrString(ifRoot interface{}, notRoot interface{}) string
The same as RootOr, but returns a string.
func TrapSignals ¶ added in v1.7.33
Registers a list of OS signals to intercept and provides an opportunity to run a function before the program exits.
func Which ¶ added in v1.7.10
Locates the first path containing the given command. The directories listed in the environment variable "PATH" will be checked, in order. If additional directories are specified in the path variadic argument, they will be checked first. If the command is not in any path, an empty string will be returned.
func WhichAll ¶ added in v1.7.10
Locates the all paths containing the given command. The directories listed in the environment variable "PATH" will be checked, in order. If additional directories are specified in the path variadic argument, they will be checked first. If the command is not in any path, an empty slice will be returned.
Types ¶
type Cmd ¶
type Cmd struct { *exec.Cmd // An interval of time on which the command should be actively checked for run and exit status. MonitorInterval time.Duration // How long the command may run for before being killed. Timeout time.Duration // Whether the command invocation should inherit the environment variables of the calling process. InheritEnv bool // Called when immediately before the command is executed. OnStart CommandStatusFunc // Called whenever the monitor check is performed. OnMonitor CommandStatusFunc // Called when the command exits, regardless of success or failure. OnComplete CommandStatusFunc // Called when the command exits with a non-error status (code 0) OnSuccess CommandStatusFunc // Called when the command exits with an error status (non-zero exit code, security, invocation, or resource error) OnError CommandStatusFunc // Called when a line of standard output is written. OnStdout OutputLineFunc // Called when a line of standard error is written. OnStderr OutputLineFunc // If specified, this function will determine how to tokenize the stdout stream and when to call OnStdout. Defaults to bufio.ScanLines. StdoutSplitFunc bufio.SplitFunc // If specified, this function will determine how to tokenize the stderr stream and when to call OnStderr. Defaults to bufio.ScanLines. StderrSplitFunc bufio.SplitFunc // contains filtered or unexported fields }
A wrapper for exec.Cmd that provides helpful callbacks and monitoring details that are challenging to implement.
func ShellCommand ¶ added in v1.7.30
func (*Cmd) CombinedOutput ¶
func (*Cmd) WaitStatus ¶
Wait for the process to complete, then return the last status. Process must have been started using the Start() function.
type CommandStatusFunc ¶
type CommandStatusFunc func(Status)