command

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exists

func Exists(name string) bool

Exists checks if a command exists in PATH

func MustRun

func MustRun(name string, args ...string) string

MustRun runs a command and panics on error (for test setup)

func RunBash

func RunBash(script string) (string, error)

RunBash runs a bash command

func RunBashInDir

func RunBashInDir(dir, script string) (string, error)

RunBashInDir runs a bash script in a specific directory

func RunInDir

func RunInDir(dir, name string, args ...string) (string, error)

RunInDir runs a command in a specific directory

func RunSimple

func RunSimple(name string, args ...string) (string, error)

RunSimple runs a simple command and returns stdout

func RunWithEnv

func RunWithEnv(env []string, name string, args ...string) (string, error)

RunWithEnv runs a command with additional environment variables

Types

type Command

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

Command represents a command to execute

func New

func New(name string, args ...string) *Command

New creates a new command

func (*Command) CombinedOutput

func (c *Command) CombinedOutput() (string, error)

CombinedOutput runs the command and returns combined stdout/stderr

func (*Command) Dir

func (c *Command) Dir(dir string) *Command

Dir sets the working directory

func (*Command) Env

func (c *Command) Env(env ...string) *Command

Env adds environment variables

func (*Command) Environment

func (c *Command) Environment() []string

Environment returns the environment variables set for this command

func (*Command) Output

func (c *Command) Output() (string, error)

Output runs the command and returns stdout on success

func (*Command) Run

func (c *Command) Run() *Result

Run executes the command and waits for completion

func (*Command) RunContext

func (c *Command) RunContext(ctx context.Context) *Result

RunContext executes the command with a custom context

func (*Command) RunStreaming

func (c *Command) RunStreaming(opts StreamOptions) *Result

RunStreaming executes the command with streaming output

func (*Command) Start

func (c *Command) Start() (*Process, error)

Start executes the command in the background.

func (*Command) Stdin

func (c *Command) Stdin(r io.Reader) *Command

Stdin sets the standard input

func (*Command) String

func (c *Command) String() string

String returns a string representation of the command

func (*Command) Timeout

func (c *Command) Timeout(d time.Duration) *Command

Timeout sets the command timeout

type ContainerInfo

type ContainerInfo struct {
	ID     string
	Name   string
	Image  string
	Status string
	Ports  []string
}

ContainerInfo represents basic container information

type Docker

type Docker struct{}

Docker provides helpers for docker commands

func NewDocker

func NewDocker() *Docker

NewDocker creates a new Docker command helper

func (*Docker) ContainerExists

func (d *Docker) ContainerExists(name string) (bool, error)

ContainerExists checks if a container exists

func (*Docker) ListContainers

func (d *Docker) ListContainers(filter string) ([]ContainerInfo, error)

ListContainers lists running containers

func (*Docker) Logs

func (d *Docker) Logs(container string, tail int) (string, error)

Logs gets container logs

func (*Docker) RemoveContainer

func (d *Docker) RemoveContainer(name string) error

RemoveContainer removes a container

func (*Docker) StopContainer

func (d *Docker) StopContainer(name string) error

StopContainer stops a container

type Grove

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

Grove provides helpers for running grove commands

func NewGrove

func NewGrove(binary string) *Grove

NewGrove creates a new Grove command helper

func (*Grove) AgentDown

func (g *Grove) AgentDown() error

AgentDown stops the grove agent

func (*Grove) AgentUp

func (g *Grove) AgentUp(detached bool) error

AgentUp starts the grove agent

func (*Grove) InDir

func (g *Grove) InDir(dir string) *Grove

InDir sets the working directory for grove commands

func (*Grove) Output

func (g *Grove) Output(args ...string) (string, error)

Output runs a grove command and returns stdout

func (*Grove) Run

func (g *Grove) Run(args ...string) *Result

Run executes a grove command

func (*Grove) ServiceDown

func (g *Grove) ServiceDown(service string) error

ServiceDown stops a service

func (*Grove) ServiceUp

func (g *Grove) ServiceUp(service string, detached bool) error

ServiceUp starts a service

func (*Grove) Status

func (g *Grove) Status() (string, error)

Status gets grove status

type Process

type Process struct {
	Cmd *exec.Cmd
	PID int
	// contains filtered or unexported fields
}

Process represents a running background command.

func (*Process) Kill

func (p *Process) Kill() error

Kill terminates the process.

func (*Process) Stderr

func (p *Process) Stderr() string

Stderr returns the standard error captured so far.

func (*Process) Stdout

func (p *Process) Stdout() string

Stdout returns the standard output captured so far.

func (*Process) Wait

func (p *Process) Wait(timeout time.Duration) *Result

Wait blocks until the process completes or the timeout is reached.

type Result

type Result struct {
	Stdout   string
	Stderr   string
	ExitCode int
	Duration time.Duration
	Error    error
}

Result contains the output and status of a command execution

func (*Result) AssertExitCode

func (r *Result) AssertExitCode(expectedCode int) error

AssertExitCode asserts that the command exited with the specified code.

func (*Result) AssertFailure

func (r *Result) AssertFailure() error

AssertFailure asserts that the command failed (non-zero exit code or error).

func (*Result) AssertStderrContains

func (r *Result) AssertStderrContains(patterns ...string) error

AssertStderrContains asserts that stderr contains all the specified patterns.

func (*Result) AssertStderrEmpty

func (r *Result) AssertStderrEmpty() error

AssertStderrEmpty asserts that stderr is empty.

func (*Result) AssertStderrNotContains

func (r *Result) AssertStderrNotContains(patterns ...string) error

AssertStderrNotContains asserts that stderr does not contain any of the specified patterns.

func (*Result) AssertStdoutContains

func (r *Result) AssertStdoutContains(patterns ...string) error

AssertStdoutContains asserts that stdout contains all the specified patterns. Returns the first assertion error encountered, or nil if all patterns are found.

func (*Result) AssertStdoutEmpty

func (r *Result) AssertStdoutEmpty() error

AssertStdoutEmpty asserts that stdout is empty.

func (*Result) AssertStdoutNotContains

func (r *Result) AssertStdoutNotContains(patterns ...string) error

AssertStdoutNotContains asserts that stdout does not contain any of the specified patterns.

func (*Result) AssertSuccess

func (r *Result) AssertSuccess() error

AssertSuccess asserts that the command succeeded (exit code 0, no error).

type StreamHandler

type StreamHandler func(line string, isStderr bool)

StreamHandler is called for each line of output

type StreamOptions

type StreamOptions struct {
	Handler       StreamHandler
	BufferSize    int
	CombineOutput bool
}

StreamOptions configures output streaming

Jump to

Keyboard shortcuts

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