cmdexec

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: GPL-3.0, LGPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package cmdexec provides a testable abstraction for running external commands.

Index

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)
}

Executor runs external commands and captures their output.

type LogFunc

type LogFunc func(ctx context.Context, cmd string)

LogFunc is called before each command execution with the context and the full command string (name + args joined by spaces).

type LoggingExecutor

type LoggingExecutor struct {
	Inner Executor
	Log   LogFunc
}

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.

func (*LoggingExecutor) RunWithStdin

func (l *LoggingExecutor) RunWithStdin(ctx context.Context, stdin io.Reader, name string, args ...string) (string, string, error)

RunWithStdin implements Executor.

type OSExecutor

type OSExecutor struct{}

OSExecutor runs commands using os/exec.

func (*OSExecutor) Run

func (e *OSExecutor) Run(ctx context.Context, name string, args ...string) (string, string, error)

Run implements Executor.

func (*OSExecutor) RunWithStdin

func (e *OSExecutor) RunWithStdin(ctx context.Context, stdin io.Reader, name string, args ...string) (string, string, error)

RunWithStdin implements Executor.

Jump to

Keyboard shortcuts

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