lordcommander

package module
v0.0.0-...-c4f1b72 Latest Latest
Warning

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

Go to latest
Published: May 9, 2016 License: MIT Imports: 9 Imported by: 0

README

lord-commander

Testable Go library to shell out with style

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAlreadyUsed is an error that a Commander returns when an attempt
	// it made to reuse it.
	ErrAlreadyUsed = NewError("commander already used")

	// ErrNonZero is an error that a Commander returns when the command
	// finishes but the process return code is not 0.
	ErrNonZero = NewError("command exited with non-zero status")
)

Functions

func NewError

func NewError(message string) error

NewError is an Error constructor.

Types

type Commander

type Commander interface {
	// Run executes the command with the same arguments as exec.Cmd.
	Run(command string, args ...string) error

	// Stdout returns standard output of the process as captured by the
	// underlying bytes.Buffer.
	Stdout() *bytes.Buffer

	// Stderr returns standard error of the process as captured by the
	// underlying bytes.Buffer.
	Stderr() *bytes.Buffer
}

Commander is a testable interface built to capture the complexities of shelling out in Go.

func New

func New(opts ...Option) Commander

New is a constructor for an actual implementation of the Commander interface, allowing it to be customized using Option functions.

type Error

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

Error is a strongly typed error for the Commander module. Having these sort of errors can make our Bugsnag look more readable.

func (*Error) Error

func (e *Error) Error() string

type MockCommander

type MockCommander struct {
	mock.Mock
}

MockCommander is a mock implementation of lordcommander.Commander.

func (*MockCommander) Run

func (mc *MockCommander) Run(command string, args ...string) error

Run is a mock implementation of Commander's Run method.

func (*MockCommander) Stderr

func (mc *MockCommander) Stderr() *bytes.Buffer

Stderr is a mock implementation of Commander's Stderr method.

func (*MockCommander) Stdout

func (mc *MockCommander) Stdout() *bytes.Buffer

Stdout is a mock implementation of Commander's Stdout method.

type Option

type Option func(*commanderImpl)

Option is a function that can be passed to a Commander's constructor to change it's default behavior.

func DiscardStderr

func DiscardStderr() Option

DiscardStderr tells the Commander not to capture standard error.

func DiscardStdout

func DiscardStdout() Option

DiscardStdout tells the Commander not to capture standard output.

func WithContext

func WithContext(ctx context.Context) Option

WithContext allows changing Commander's default context.

func WithEnvironment

func WithEnvironment(env []string) Option

WithEnvironment allows changing Commander's default environment.

func WithSignal

func WithSignal(signal os.Signal) Option

WithSignal allows changing Commander's default termination signal.

func WithStdin

func WithStdin(stdin io.Reader) Option

WithStdin allows changing Commander's default standard input.

Jump to

Keyboard shortcuts

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