exec

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2022 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

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 (*Cmd) DebugfFunc

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

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

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

Directory changes the directory in which the command is executed.

func (*Cmd) Env

func (c *Cmd) Env(env []string) *Cmd

Env specifies the environment variables that the process uses. Each element is in the format KEY=VALUE.

func (*Cmd) ExpectSuccess

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

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

Run executes the command.

type ExitCodeError

type ExitCodeError struct {
	*Result
}

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

func (ExitCodeError) Error

func (e ExitCodeError) Error() string

Error returns the error description.

type Result

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

Result describes the result of a run Cmd.

func (*Result) ExpectSuccess

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

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