cmd

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*options)

Option is a functional option for configuring command execution.

func WithArgs

func WithArgs(args ...string) Option

WithArgs sets the arguments with varargs. No quoting or escaping is performed. The caller is responsible for any necessary quoting/escaping.

func WithArgsString

func WithArgsString(argsStr string) Option

WithArgsString sets the arguments from a string using shell-style parsing. The string is split using github.com/google/shlex which handles: - Whitespace splitting - Single and double quote handling - Escape sequences Example: WithArgsString(`-f "file name.txt" --mode=fast`)

func WithCombinedOutput

func WithCombinedOutput() Option

WithCombinedOutput captures stdout and stderr together in Combined field.

func WithDir

func WithDir(dir string) Option

WithDir sets the working directory for the command.

func WithDiscard

func WithDiscard() Option

WithDiscard sends stdout/stderr to io.Discard (but still captures).

func WithEcho

func WithEcho(enable bool) Option

WithEcho enables or disables command echoing (default: true).

func WithEchoWriter

func WithEchoWriter(w io.Writer) Option

WithEchoWriter sets where to write the command echo (default: os.Stdout).

func WithEnv

func WithEnv(env []string) Option

WithEnv sets environment variables for the command.

func WithPassthrough

func WithPassthrough() Option

WithPassthrough sends stdout and stderr to os.Stdout AND captures them separately.

func WithStdin

func WithStdin(r io.Reader) Option

WithStdin sets the stdin for the command.

type Result

type Result struct {
	Stdout   string
	Stderr   string
	Combined string
	ExitCode int
}

Result holds the output and exit code from a command execution.

func Run

func Run(name string, opts ...Option) (*Result, error)

Run executes a command with default options.

func RunContext

func RunContext(ctx context.Context, name string, opts ...Option) (*Result, error)

RunContext executes a command with context and options.

Jump to

Keyboard shortcuts

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