executil

package
v1.7.35 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2019 License: MIT Imports: 17 Imported by: 16

Documentation

Overview

Utilities that make executing commands on the local system a little bit easier.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 IsRoot added in v1.7.31

func IsRoot() bool

Returns whether the current user is root or not.

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

func TrapSignals(after func(sig os.Signal) bool, signals ...os.Signal)

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

func Which(cmdname string, path ...string) string

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

func WhichAll(cmdname string, path ...string) []string

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
	MonitorInterval time.Duration
	Timeout         time.Duration
	InheritEnv      bool
	OnStart         CommandStatusFunc
	OnMonitor       CommandStatusFunc
	OnComplete      CommandStatusFunc
	OnSuccess       CommandStatusFunc
	OnError         CommandStatusFunc
	// contains filtered or unexported fields
}

func Command

func Command(name string, arg ...string) *Cmd

func CommandContext

func CommandContext(ctx context.Context, name string, arg ...string) *Cmd

func ShellCommand added in v1.7.30

func ShellCommand(cmdline string) *Cmd

func Wrap

func Wrap(cmd *exec.Cmd) *Cmd

func (*Cmd) CombinedOutput

func (self *Cmd) CombinedOutput() ([]byte, error)

func (*Cmd) Kill added in v1.7.30

func (self *Cmd) Kill() error

Kill the running command.

func (*Cmd) Output

func (self *Cmd) Output() ([]byte, error)

func (*Cmd) Run

func (self *Cmd) Run() error

func (*Cmd) SetEnv added in v1.7.30

func (self *Cmd) SetEnv(key string, value interface{})

func (*Cmd) Start

func (self *Cmd) Start() error

func (*Cmd) Status

func (self *Cmd) Status() Status

Return the current status of the process.

func (*Cmd) WaitStatus

func (self *Cmd) WaitStatus() Status

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)

type Status

type Status struct {
	StartedAt  time.Time
	StoppedAt  time.Time
	Running    bool
	Successful bool
	ExitCode   int
	Error      error
	PID        int
}

func (Status) String

func (self Status) String() string

func (Status) Took

func (self Status) Took() time.Duration

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL