exec

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: GPL-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultLogFn is the default debug print function.
	DefaultLogFn = func(string, ...interface{}) {}
	// DefaultLogPrefix is the default prefix that is prepended to messages passed to the debugf function.
	DefaultLogPrefix = "exec: "
	// DefaultStderrColorFn is the default function that is used to colorize stderr output that is streamed to the log function.
	DefaultStderrColorFn = color.New(color.FgRed).SprintFunc()
)

Functions

This section is empty.

Types

type Cmd

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

func Command

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

Command returns an executable representation of a Command.

func (*Cmd) Directory

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

Directory defines the directiory in which the command is executed.

func (*Cmd) Env

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

Env defines environment variables that are set during execution.

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) LogFn added in v3.1.0

func (c *Cmd) LogFn(fn PrintfFn) *Cmd

LogFn sets a Printf-style function as logger.

func (*Cmd) LogPrefix added in v3.1.0

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

LogPrefix defines a string that is used as prefix for all messages written via *Cmd.LogFn.

func (*Cmd) Run

func (c *Cmd) Run(ctx context.Context) (*Result, error)

Run executes the command.

func (*Cmd) RunCombinedOut added in v3.1.0

func (c *Cmd) RunCombinedOut(ctx context.Context) (*ResultOut, error)

RunCombinedOut executes the command and stores the combined stdout and stderr output of the process in ResultOut.CombinedOutput.

func (*Cmd) Stderr added in v3.1.0

func (c *Cmd) Stderr(w io.Writer) *Cmd

Stdout streams the standard error output to w during execution.

func (*Cmd) Stdout added in v3.1.0

func (c *Cmd) Stdout(w io.Writer) *Cmd

Stdout streams the standard output to w during execution.

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 PrintfFn added in v3.1.0

type PrintfFn func(format string, a ...any)

type Result

type Result struct {
	Command  string
	Dir      string
	ExitCode int
	// contains filtered or unexported fields
}

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.

type ResultOut added in v3.1.0

type ResultOut struct {
	*Result
	CombinedOutput []byte
}

func (*ResultOut) StrOutput added in v3.1.0

func (r *ResultOut) StrOutput() string

Jump to

Keyboard shortcuts

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