exec

package
v0.0.0-...-606a1df Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExecutableNotFound = osexec.ErrNotFound

ErrExecutableNotFound is returned if the executable is not found.

Functions

This section is empty.

Types

type Cmd

type Cmd interface {
	// CombinedOutput runs the command and returns its combined standard output
	// and standard error.  This follows the pattern of package os/exec.
	CombinedOutput() ([]byte, error)
	// Output runs the command and returns standard output, but not standard err
	Output() ([]byte, error)
	SetDir(dir string)
	SetStdin(in io.Reader)
	SetStdout(out io.Writer)
}

Cmd is an interface that presents an API that is very similar to Cmd from os/exec. As more functionality is needed, this can grow. Since Cmd is a struct, we will have to replace fields with get/set method pairs.

type CodeExitError

type CodeExitError struct {
	Err  error
	Code int
}

CodeExitError is an implementation of ExitError consisting of an error object and an exit code (the upper bits of os.exec.ExitStatus).

func (CodeExitError) Error

func (e CodeExitError) Error() string

func (CodeExitError) ExitStatus

func (e CodeExitError) ExitStatus() int

func (CodeExitError) Exited

func (e CodeExitError) Exited() bool

func (CodeExitError) String

func (e CodeExitError) String() string

type ExitError

type ExitError interface {
	String() string
	Error() string
	Exited() bool
	ExitStatus() int
}

ExitError is an interface that presents an API similar to os.ProcessState, which is what ExitError from os/exec is. This is designed to make testing a bit easier and probably loses some of the cross-platform properties of the underlying library.

type ExitErrorWrapper

type ExitErrorWrapper struct {
	*osexec.ExitError
}

ExitErrorWrapper is an implementation of ExitError in terms of os/exec ExitError. Note: standard exec.ExitError is type *os.ProcessState, which already implements Exited().

func (ExitErrorWrapper) ExitStatus

func (eew ExitErrorWrapper) ExitStatus() int

ExitStatus is part of the ExitError interface.

type Interface

type Interface interface {
	// Command returns a Cmd instance which can be used to run a single command.
	// This follows the pattern of package os/exec.
	Command(cmd string, args ...string) Cmd
	CommandContext(ctx context.Context, cmd string, args ...string) Cmd

	// LookPath wraps os/exec.LookPath
	LookPath(file string) (string, error)
}

Interface is an interface that presents a subset of the os/exec API. Use this when you want to inject fakeable/mockable exec behavior.

func New

func New() Interface

New returns a new Interface which will os/exec to run commands.

Jump to

Keyboard shortcuts

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