Documentation ¶
Overview ¶
Package sh helps you to more easily execute processes.
Index ¶
- func Expand(value string, expander Expander) string
- type Expander
- type OutputOptions
- type Sh
- func (sh *Sh) Cmd() *exec.Cmd
- func (this *Sh) CommandLog(commandLog io.Writer) *Sh
- func (this *Sh) CommandLogPrefix(prefix string) *Sh
- func (this *Sh) Dir(dir string) *Sh
- func (this *Sh) Env(env map[string]string) *Sh
- func (sh *Sh) Exec() (err error)
- func (sh *Sh) ExitCode() int
- func (this *Sh) Expand(expander Expander) *Sh
- func (this *Sh) Line(commandLine string) *Sh
- func (this *Sh) LineArgs(commandLIne ...string) *Sh
- func (sh *Sh) MustExec()
- func (sh *Sh) MustZeroExit()
- func (sh *Sh) Output(opt ...OutputOptions) (output string, exitCode int, err error)
- func (sh *Sh) Run() error
- func (this *Sh) Stderr(writer io.Writer) *Sh
- func (this *Sh) Stdin(reader io.Reader) *Sh
- func (this *Sh) Stdout(writer io.Writer) *Sh
- func (sh *Sh) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Expander ¶
type Expander interface { // Expand retrieves the value of the variable named // by the key. If the variable is found the // value (which may be empty) is returned and the boolean is true. // Otherwise the returned value will be empty and the boolean will // be false. Expand(key string) (value string, ok bool) }
An Expander is used to expand/resolve a variable name to a value
func ChainExpanders ¶
Expanders creates an Expander that expands using the provided list of Expanders in order.
You can use this to customize how key not found scenarios are handled. If you want to panic if the key is not found in the OS Env you could build that expander like:
exp := ChainExpanders(ExpandEnv(), ExpandPanic())
func ExpandDisabled ¶
func ExpandDisabled() Expander
ExpandDisabled returns an Expander that evaluates to the same string that describes the expansion.
func ExpandEnv ¶
func ExpandEnv() Expander
ExpandEnv returns an Expander that expands values from the operating system environment.
func ExpandNotFound ¶
func ExpandNotFound() Expander
ExpandNotFound returns an Expander that never finds the value being expanded.
func ExpandPanic ¶
func ExpandPanic() Expander
ExpandPanic returns an Expander that panics when used.
type OutputOptions ¶
type Sh ¶
type Sh struct {
// contains filtered or unexported fields
}
Sh contains all the settings needed to execute process. It is guarded by an immutable builder access model.
func (*Sh) CommandLog ¶
CommandLog returns a new sh.Sh configured io.Writer that will receive the fully expanded command when the process is executed.
func (*Sh) CommandLogPrefix ¶
CommandLogPrefix returns a new sh.Sh configured with a prfefix to use when logging executed commands.
func (*Sh) Env ¶
Line returns a new sh.Sh configured with additional env variables to pass to the executed process
func (*Sh) Exec ¶
Exec uses the exec system call to execute the sh.Sh command. When Exec is called the previous go process is replaced by the executed command. Exec panics if called on a sh.Sh that has the default Stdout, Stderr, or Stdin changed. Returns an error if the process cannot be executed.
func (*Sh) ExitCode ¶
ExitStatus runs the command and returns the process exit code, or 1 if any other error occured.
func (*Sh) Expand ¶
Line returns a new sh.Sh configured with an Expander to control variable expansion. Use Expand(ExpandDisabled()) to disable expanding variables.
func (*Sh) Line ¶
Line returns a new sh.Sh with the command specified as a single command. The command line is parsed into command line arguments. You can use single and double quotes like you do in bash to group command line arguments. Single quoted strings will have variable expansion disabled.
func (*Sh) MustExec ¶
func (sh *Sh) MustExec()
MustExec runs the process and panics if it returns a non zero exit code..
func (*Sh) MustZeroExit ¶
func (sh *Sh) MustZeroExit()
MustExec runs the process and panics if it returns a non zero exit code..
func (*Sh) Output ¶
func (sh *Sh) Output(opt ...OutputOptions) (output string, exitCode int, err error)
func (*Sh) Stderr ¶
Stderr returns a new sh.Sh configured to write process stderr with the specified writer.
func (*Sh) Stdin ¶
Stdin returns a new sh.Sh configured feed process stdin with the specified reader.