command

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the default command execution timeout
	DefaultTimeout = 2 * time.Minute

	// MaxTimeout is the maximum allowed timeout
	MaxTimeout = 10 * time.Minute
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command represents a safe command configuration

func (*Command) Exec

func (c *Command) Exec() *exec.Cmd

Exec creates and returns an exec.Cmd

func (*Command) WithTimeout

func (c *Command) WithTimeout(timeout time.Duration) *Command

WithTimeout sets a custom timeout for the command

type Executor

type Executor interface {
	// Command creates a new exec.Cmd instance for the given command and arguments.
	Command(name string, args ...string) *exec.Cmd

	// CommandContext creates a new context-aware exec.Cmd instance.
	CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd
}

Executor creates exec.Cmd instances. This abstraction allows for dependency injection, enabling test-specific command creation logic (e.g., setting up a PATH with mock binaries) without modifying production code.

type RealExecutor

type RealExecutor struct{}

RealExecutor is the production implementation of the Executor interface, which uses the standard os/exec package to create commands.

func (*RealExecutor) Command

func (e *RealExecutor) Command(name string, args ...string) *exec.Cmd

Command creates a standard exec.Cmd.

func (*RealExecutor) CommandContext

func (e *RealExecutor) CommandContext(ctx context.Context, name string, args ...string) *exec.Cmd

CommandContext creates a standard context-aware exec.Cmd.

type SafeBuilder

type SafeBuilder struct {
	// contains filtered or unexported fields
}

SafeBuilder provides secure command execution with validation

func NewSafeBuilder

func NewSafeBuilder() *SafeBuilder

NewSafeBuilder creates a new SafeBuilder instance with a RealExecutor

func NewSafeBuilderWithExecutor

func NewSafeBuilderWithExecutor(exec Executor) *SafeBuilder

NewSafeBuilderWithExecutor creates a new SafeBuilder with a custom Executor

func (*SafeBuilder) Build

func (sb *SafeBuilder) Build(ctx context.Context, name string, args ...string) (*Command, error)

Build creates a new command with validation

func (*SafeBuilder) Validate

func (sb *SafeBuilder) Validate(argType string, value string) error

Validate validates specific arguments

Jump to

Keyboard shortcuts

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