command

package
v2.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2026 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Overview

Package command provides an abstraction over exec.Command for testability.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

type Executor interface {
	// Run executes a command and waits for it to complete.
	// Returns an error if the command fails to start or exits with non-zero status.
	Run(ctx context.Context, name string, args ...string) error

	// Output runs a command and returns its standard output.
	// Returns the output bytes and an error if the command fails.
	Output(ctx context.Context, name string, args ...string) ([]byte, error)

	// Start starts a command without waiting for it to complete (fire-and-forget).
	// Returns an error if the command fails to start.
	Start(ctx context.Context, name string, args ...string) error

	// StartWithOptions starts a command with platform-specific options.
	// Returns an error if the command fails to start.
	StartWithOptions(ctx context.Context, opts StartOptions, name string, args ...string) error
}

Executor provides an abstraction over exec.Command for testability. This allows commands to be mocked in tests without executing real system commands.

type RealExecutor

type RealExecutor struct{}

RealExecutor uses actual exec.Command to execute system commands. This is the production implementation used in normal operation.

func (*RealExecutor) Output

func (*RealExecutor) Output(ctx context.Context, name string, args ...string) ([]byte, error)

Output runs a command and returns its standard output.

func (*RealExecutor) Run

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

Run executes a system command using exec.CommandContext.

func (*RealExecutor) Start

func (*RealExecutor) Start(ctx context.Context, name string, args ...string) error

Start starts a command without waiting for it to complete.

func (*RealExecutor) StartWithOptions

func (*RealExecutor) StartWithOptions(
	ctx context.Context,
	_ StartOptions,
	name string,
	args ...string,
) error

StartWithOptions starts a command with platform-specific options on Unix. HideWindow option is ignored on non-Windows platforms.

type StartOptions

type StartOptions struct {
	// HideWindow prevents a console window from appearing (Windows-only).
	// On non-Windows platforms, this field is ignored.
	HideWindow bool
}

StartOptions configures command startup behavior.

Jump to

Keyboard shortcuts

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