exec

package
v0.0.0-...-6d3478e Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCommandFailed = errors.New("Command failed to execute succcesfully")
)

errors ...

Functions

This section is empty.

Types

type Commander

type Commander struct {
	Async       bool
	Command     string
	SubCommands []string
	Timeout     time.Duration
	Dir         string
	Binary      string
	Flag        string
	Envs        map[string]string
	In          io.Reader
	Out         io.Writer
	Err         io.Writer
}

Commander runs provided command within a /bin/sh -c "{COMMAND}", returning response associatedly. It also attaches if provided stdin, stdout and stderr readers/writers. Commander allows you to set the binary to use and flag, where each defaults to /bin/sh for binary and -c for flag respectively.

func ApplyImmediate

func ApplyImmediate(cm *Commander, ops ...CommanderOption) *Commander

ApplyImmediate applies the options immediately to the Commander.

func New

func New(ops ...CommanderOption) *Commander

New returns a new Commander instance.

func (*Commander) Exec

func (c *Commander) Exec(ctx context.Context, metric metrics.Metrics) error

Exec executes giving command associated within the command with os/exec.

func (*Commander) ExecWithExitCode

func (c *Commander) ExecWithExitCode(ctx context.Context, metric metrics.Metrics) (int, error)

ExecWithExitCode executes giving command associated within the command with os/exec.

type CommanderOption

type CommanderOption func(*Commander)

CommanderOption defines a function type that aguments a commander's field.

func Apply

func Apply(ops ...CommanderOption) CommanderOption

Apply takes the giving series of CommandOption returning a function that always applies them to passed in commanders.

func Async

func Async() CommanderOption

Async sets the commander to run in asynchronouse mode.

func Binary

func Binary(bin string, flag string) CommanderOption

Binary sets the binary command for the Commander.

func Command

func Command(c string, m ...interface{}) CommanderOption

Command sets the command for the Commander.

func Commands

func Commands(p ...string) CommanderOption

Commands sets the subcommands for the Commander exec call. If subcommands are set then the Binary, Flag and Command are ignored and the values of the subcommand is used.

func Dir

func Dir(p string) CommanderOption

Dir sets the Directory for the Commander exec call.

func Envs

func Envs(envs map[string]string) CommanderOption

Envs sets the map of environment for the Commander.

func Err

func Err(err io.Writer) CommanderOption

Err sets the error writer for the Commander.

func Input

func Input(in io.Reader) CommanderOption

Input sets the input reader for the Commander.

func Output

func Output(out io.Writer) CommanderOption

Output sets the output writer for the Commander.

func SetAsync

func SetAsync(b bool) CommanderOption

SetAsync sets the command for the Commander.

func Sync

func Sync() CommanderOption

Sync sets the commander to run in synchronouse mode.

func Timeout

func Timeout(d time.Duration) CommanderOption

Timeout sets the commander to run in synchronouse mode.

Jump to

Keyboard shortcuts

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