exec

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2019 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRun occurs when a command could not be executed.
	ErrRun = errors.New("Could not execute command")
	// ErrReturnCode occurs when a command was executed but returned with a non-zero exit code.
	ErrReturnCode = errors.New("Process returned with code %d")
	// ErrParse occurs when a malformed command line was encountered.
	ErrParse = errors.New("Unable to parse command line")
	// DefaultExecutor denotes the Executor that is used by default for Run and RunLine commands.
	DefaultExecutor Executor
)

Functions

func GetCommandLine

func GetCommandLine(command string, args ...string) string

GetCommandLine is the inverse function of Parse. It assembles a single command line that is equivalent to the given command and arguments by escaping and quoting.

func Parse

func Parse(commandLine string) (string, []string, errors.Error)

Parse returns the command and arguments from a command line.

func Quote

func Quote(str string) string

Quote returns a safe representation of the given string for command line calls.

func Run

func Run(command string, args ...string) (string, int, errors.Error)

Run executes a command with given arguments using the DefaultExecutor.

func RunLine

func RunLine(commandLine string) (string, int, errors.Error)

RunLine parses the given command line and runs it using the DefaultExecutor.

func ShouldRun added in v1.0.1

func ShouldRun(command string, args ...string) (string, errors.Error)

ShouldRun executes the given command using Run but returns an error for non-zero return codes.

func ShouldRunLine added in v1.0.1

func ShouldRunLine(commandLine string) (string, errors.Error)

ShouldRunLine executes the given command using RunLine but returns an error for non-zero return codes.

Types

type Executor

type Executor interface {
	// RunLine executes an escaped single string command line.
	RunLine(commandLine string) (string, int, errors.Error)
	// Run executes a command line with separated arguments.
	Run(command string, args ...string) (string, int, errors.Error)
}

Executor represents the interface for shell command execution.

type LocalExecutor

type LocalExecutor struct {
}

LocalExecutor is used to execute commands on the local shell.

func NewLocalExecutor

func NewLocalExecutor() *LocalExecutor

NewLocalExecutor returns an executor for the local shell.

func (*LocalExecutor) Run

func (e *LocalExecutor) Run(command string, args ...string) (string, int, errors.Error)

Run executes a command line with separated arguments.

func (*LocalExecutor) RunLine

func (e *LocalExecutor) RunLine(commandLine string) (string, int, errors.Error)

RunLine executes an escaped single string command line.

type MockExecutor

type MockExecutor struct {
	RunCallback func(command string, args ...string) (string, int, errors.Error)
}

MockExecutor offers functionality to mock and debug executed commands.

func NewMockExecutor

func NewMockExecutor(runCallback func(command string, args ...string) (string, int, errors.Error)) *MockExecutor

NewMockExecutor returns an executor for the local shell.

func (*MockExecutor) Run

func (e *MockExecutor) Run(command string, args ...string) (string, int, errors.Error)

Run calls runCallback.

func (*MockExecutor) RunLine

func (e *MockExecutor) RunLine(commandLine string) (string, int, errors.Error)

RunLine parses the command and calls RunCallback.

Jump to

Keyboard shortcuts

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