Documentation ¶
Overview ¶
Package exechelper provides a wrapper around cmd.Exec that makes it easier to use
Index ¶
- func CombinedOutput(cmdStr string, options ...*Option) ([]byte, error)
- func Output(cmdStr string, options ...*Option) ([]byte, error)
- func Run(cmdStr string, options ...*Option) error
- func Start(cmdStr string, options ...*Option) <-chan error
- type CmdFunc
- type Option
- func CmdOption(cmdFunc CmdFunc) *Option
- func WithArgs(args ...string) *Option
- func WithContext(ctx context.Context) *Option
- func WithDir(dir string) *Option
- func WithEnvKV(envs ...string) *Option
- func WithEnvMap(envMap map[string]string) *Option
- func WithEnvirons(environs ...string) *Option
- func WithGracePeriod(gracePeriod time.Duration) *Option
- func WithNetNS(handle netns.NsHandle) *Option
- func WithOnDeathSignalChildren(signal syscall.Signal) *Option
- func WithStderr(writer io.Writer) *Option
- func WithStdin(reader io.Reader) *Option
- func WithStdout(writer io.Writer) *Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CombinedOutput ¶
CombinedOutput - Creates a exec.Cmd using cmdStr. Runs exec.Cmd.CombinedOutput and returns the resulting output as []byte and error
func Output ¶
Output - Creates a exec.Cmd using cmdStr. Runs exec.Cmd.Output and returns the resulting output as []byte and error
Types ¶
type Option ¶
type Option struct { // Context - context (if any) for running the exec.Cmd Context context.Context // SIGTERM grace period GracePeriod time.Duration // CmdFunc to be applied to the exec.Cmd CmdOption CmdFunc // PostRunOption - CmdFunc to be applied to the exec.Cmd after running PostRunOption CmdFunc }
Option - expresses optional behavior for exec.Cmd
func CmdOption ¶
CmdOption - convenience function for producing an Option that only has an Option.CmdOption
func WithArgs ¶
WithArgs - appends additional args to cmdStr
useful for ensuring correctness when you start from args []string rather than from a cmdStr to be parsed
func WithContext ¶
WithContext - option for setting the context.Context for running the exec.Cmd
func WithDir ¶
WithDir - Option that will create the requested dir if it does not exist and set exec.Cmd.Dir = dir
func WithEnvKV ¶
WithEnvKV - add entries to exec.Cmd as a series key,value pairs in a list of strings Existing instances of 'key' will be overwritten Example: WithEnvKV(key1,value2,key2,value2...)
func WithEnvMap ¶
WithEnvMap - add entries to exec.Cmd from envMap Existing instances of 'key' will be overwritten Example: WithEnvKV(map[string]string{key1:value1,key2:value2})
func WithEnvirons ¶
WithEnvirons - add entries to exec.Cmd.Env as a series of "key=value" strings Example: WithEnvirons("key1=value1","key2=value2",...)
func WithGracePeriod ¶ added in v1.0.2
WithGracePeriod - will send a SIGTERM when ctx.Done() and wait up to gracePeriod before SIGKILLing the process.
func WithNetNS ¶ added in v1.0.3
WithNetNS - run the cmd in the network namespace (netNS) specified by handle.
func WithOnDeathSignalChildren ¶ added in v1.0.2
WithOnDeathSignalChildren - set the signal that will be sent to children of process on processes death (only available on linux)
func WithStderr ¶
WithStderr - option to provide a writer to receive exec.Cmd.Stderr
if multiple WithStderr options are received, they are combined with an io.Multiwriter
func WithStdout ¶
WithStdout - option to provide a writer to receive exec.Cmd.Stdout
if multiple WithStdout options are received, they are combined with an io.Multiwriter