Documentation
¶
Overview ¶
Package cmdexec provides a testable abstraction for running external commands.
Index ¶
- type Executor
- type LogFunc
- type LoggingExecutor
- func (l *LoggingExecutor) Run(ctx context.Context, name string, args ...string) (string, string, error)
- func (l *LoggingExecutor) RunWithStdin(ctx context.Context, stdin io.Reader, name string, args ...string) (string, string, error)
- func (l *LoggingExecutor) Start(ctx context.Context, name string, args ...string) (*Process, error)
- type OSExecutor
- func (e *OSExecutor) Run(ctx context.Context, name string, args ...string) (string, string, error)
- func (e *OSExecutor) RunWithStdin(ctx context.Context, stdin io.Reader, name string, args ...string) (string, string, error)
- func (e *OSExecutor) Start(ctx context.Context, name string, args ...string) (*Process, error)
- type Process
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executor ¶
type Executor interface {
// Run executes the named command with the given arguments and returns
// the captured stdout and stderr. If the command exits with a non-zero
// status, the returned error wraps an *exec.ExitError.
Run(ctx context.Context, name string, args ...string) (stdout string, stderr string, err error)
// RunWithStdin is like Run but pipes the given reader to the command's stdin.
RunWithStdin(ctx context.Context, stdin io.Reader, name string, args ...string) (stdout string, stderr string, err error)
// Start starts a long-lived command and returns a Process for reading
// its stdout incrementally. The command is killed when ctx is cancelled.
// The caller must call Process.Close to release resources.
Start(ctx context.Context, name string, args ...string) (*Process, error)
}
Executor runs external commands and captures their output.
type LogFunc ¶
LogFunc is called before each command execution with the context and the full command string (name + args joined by spaces).
type LoggingExecutor ¶
LoggingExecutor wraps another Executor and calls a LogFunc before each command invocation.
func (*LoggingExecutor) Run ¶
func (l *LoggingExecutor) Run(ctx context.Context, name string, args ...string) (string, string, error)
Run implements Executor.
type OSExecutor ¶
type OSExecutor struct{}
OSExecutor runs commands using os/exec.
type Process ¶ added in v0.9.0
type Process struct {
Stdout io.ReadCloser
// contains filtered or unexported fields
}
Process represents a running long-lived command whose stdout can be read incrementally. The caller must call Close to release resources.
func Start ¶ added in v0.9.0
Start starts a command and returns a Process for reading its stdout. The command is killed when ctx is cancelled.