exec

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: GPL-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package exec runs external commands

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDebugfFn is the default debug print function.
	DefaultDebugfFn = func(string, ...interface{}) {}
	// DefaultDebugPrefix is the default prefix that is prepended to messages passed to the debugf function.
	DefaultDebugPrefix = "exec: "
)

Functions

This section is empty.

Types

type Cmd added in v0.15.0

type Cmd struct {
	// contains filtered or unexported fields
}

Cmd represents a command that can be run.

func Command

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

Command returns a new Cmd struct. If name contains no path separators, Command uses LookPath to resolve name to a complete path if possible. Otherwise it uses name directly as Path. By default a command is run in the current working directory.

func ShellCommand added in v0.15.0

func ShellCommand(cmd string) *Cmd

ShellCommand executes a command in sh shell.

func (*Cmd) DebugfFunc added in v0.15.0

func (c *Cmd) DebugfFunc(fn func(format string, arg ...interface{})) *Cmd

DebugfFunc sets the debug function for the command. It accepts a printf-style printf function and call it for every line that the command prints to STDOUT and STDERR when it's run.

func (*Cmd) DebugfPrefix added in v0.15.0

func (c *Cmd) DebugfPrefix(prefix string) *Cmd

DebugfPrefix sets a prefix that is prepended to the message that is passed to the Debugf function.

func (*Cmd) Directory added in v0.15.0

func (c *Cmd) Directory(dir string) *Cmd

Directory changes the directory in which the command is executed.

func (*Cmd) ExpectSuccess added in v0.15.0

func (c *Cmd) ExpectSuccess() *Cmd

ExpectSuccess if called, Run() will return an error if the command did not exit with code 0.

func (*Cmd) Run added in v0.15.0

func (c *Cmd) Run() (*Result, error)

Run executes the command.

type ExitCodeError added in v0.15.0

type ExitCodeError struct {
	*Result
}

ExitCodeError is returned from Run() when a command exited with a code != 0.

func (ExitCodeError) Error added in v0.15.0

func (e ExitCodeError) Error() string

Error returns the error description.

type Result added in v0.15.0

type Result struct {
	Command  string
	Dir      string
	Output   []byte
	ExitCode int
}

Result describes the result of a run Cmd.

func (*Result) ExpectSuccess added in v0.15.0

func (r *Result) ExpectSuccess() error

ExpectSuccess if the ExitCode in Result is not 0, the function returns an ExitCodeError for the execution.

func (*Result) StrOutput added in v0.15.0

func (r *Result) StrOutput() string

StrOutput returns Result.Output as string.

Jump to

Keyboard shortcuts

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