shell

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: Apache-2.0 Imports: 13 Imported by: 193

Documentation

Overview

Package shell allows to run commands in a shell.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExitCodeForRunCommandError

func GetExitCodeForRunCommandError(err error) (int, error)

GetExitCodeForRunCommandError tries to read the exit code for the error object returned from running a shell command. This is a bit tricky to do in a way that works across platforms.

func RunCommand deprecated

func RunCommand(t testing.TestingT, command Command)

RunCommand runs a shell command and redirects its stdout and stderr to the stdout of the atomic script itself. If there are any errors, fail the test.

Deprecated: Use RunCommandContext instead.

func RunCommandAndGetOutput deprecated

func RunCommandAndGetOutput(t testing.TestingT, command Command) string

RunCommandAndGetOutput runs a shell command and returns its stdout and stderr as a string. The stdout and stderr of that command will also be logged with Command.Log to make debugging easier. If there are any errors, fail the test.

Deprecated: Use RunCommandContextAndGetOutput instead.

func RunCommandAndGetOutputE deprecated

func RunCommandAndGetOutputE(t testing.TestingT, command Command) (string, error)

RunCommandAndGetOutputE runs a shell command and returns its stdout and stderr as a string. The stdout and stderr of that command will also be logged with Command.Log to make debugging easier. Any returned error will be of type ErrWithCmdOutput, containing the output streams and the underlying error.

Deprecated: Use RunCommandContextAndGetOutputE instead.

func RunCommandAndGetStdOut deprecated added in v0.17.2

func RunCommandAndGetStdOut(t testing.TestingT, command Command) string

RunCommandAndGetStdOut runs a shell command and returns solely its stdout (but not stderr) as a string. The stdout and stderr of that command will also be logged with Command.Log to make debugging easier. If there are any errors, fail the test.

Deprecated: Use RunCommandContextAndGetStdOut instead.

func RunCommandAndGetStdOutE deprecated added in v0.17.2

func RunCommandAndGetStdOutE(t testing.TestingT, command Command) (string, error)

RunCommandAndGetStdOutE runs a shell command and returns solely its stdout (but not stderr) as a string. The stdout and stderr of that command will also be printed to the stdout and stderr of this Go program to make debugging easier. Any returned error will be of type ErrWithCmdOutput, containing the output streams and the underlying error.

Deprecated: Use RunCommandContextAndGetStdOutE instead.

func RunCommandAndGetStdOutErr deprecated added in v0.48.2

func RunCommandAndGetStdOutErr(t testing.TestingT, command Command) (stdout string, stderr string)

RunCommandAndGetStdOutErr runs a shell command and returns solely its stdout and stderr as a string. The stdout and stderr of that command will also be logged with Command.Log to make debugging easier. If there are any errors, fail the test.

Deprecated: Use RunCommandContextAndGetStdOutErr instead.

func RunCommandAndGetStdOutErrE deprecated added in v0.48.2

func RunCommandAndGetStdOutErrE(t testing.TestingT, command Command) (stdout string, stderr string, err error)

RunCommandAndGetStdOutErrE runs a shell command and returns solely its stdout and stderr as a string. The stdout and stderr of that command will also be printed to the stdout and stderr of this Go program to make debugging easier. Any returned error will be of type ErrWithCmdOutput, containing the output streams and the underlying error.

Deprecated: Use RunCommandContextAndGetStdOutErrE instead.

func RunCommandContext added in v1.0.0

func RunCommandContext(t testing.TestingT, ctx context.Context, command *Command)

RunCommandContext is like RunCommand but includes a context.

func RunCommandContextAndGetOutput added in v1.0.0

func RunCommandContextAndGetOutput(t testing.TestingT, ctx context.Context, command *Command) string

RunCommandContextAndGetOutput is like RunCommandAndGetOutput but includes a context.

func RunCommandContextAndGetOutputE added in v1.0.0

func RunCommandContextAndGetOutputE(t testing.TestingT, ctx context.Context, command *Command) (string, error)

RunCommandContextAndGetOutputE is like RunCommandAndGetOutputE but includes a context.

func RunCommandContextAndGetStdOut added in v1.0.0

func RunCommandContextAndGetStdOut(t testing.TestingT, ctx context.Context, command *Command) string

RunCommandContextAndGetStdOut is like RunCommandAndGetStdOut but includes a context.

func RunCommandContextAndGetStdOutE added in v1.0.0

func RunCommandContextAndGetStdOutE(t testing.TestingT, ctx context.Context, command *Command) (string, error)

RunCommandContextAndGetStdOutE is like RunCommandAndGetStdOutE but includes a context.

func RunCommandContextAndGetStdOutErr added in v1.0.0

func RunCommandContextAndGetStdOutErr(t testing.TestingT, ctx context.Context, command *Command) (stdout string, stderr string)

RunCommandContextAndGetStdOutErr is like RunCommandAndGetStdOutErr but includes a context.

func RunCommandContextAndGetStdOutErrE added in v1.0.0

func RunCommandContextAndGetStdOutErrE(t testing.TestingT, ctx context.Context, command *Command) (stdout string, stderr string, err error)

RunCommandContextAndGetStdOutErrE is like RunCommandAndGetStdOutErrE but includes a context.

func RunCommandContextE added in v1.0.0

func RunCommandContextE(t testing.TestingT, ctx context.Context, command *Command) error

RunCommandContextE is like RunCommandE but includes a context.

func RunCommandE deprecated

func RunCommandE(t testing.TestingT, command Command) error

RunCommandE runs a shell command and redirects its stdout and stderr to the stdout of the atomic script itself. Any returned error will be of type ErrWithCmdOutput, containing the output streams and the underlying error.

Deprecated: Use RunCommandContextE instead.

Types

type Command

type Command struct {
	// Use the specified logger for the command's output. Use logger.Discard to not print the output while executing the command.
	Logger     *logger.Logger
	Stdin      io.Reader
	Env        map[string]string // Additional environment variables to set
	Command    string            // The command to run
	WorkingDir string            // The working directory
	Args       []string          // The args to pass to the command
}

Command is a simpler struct for defining commands than Go's built-in Cmd.

type ErrWithCmdOutput added in v0.28.0

type ErrWithCmdOutput struct {
	Underlying error
	Output     *output
}

ErrWithCmdOutput wraps an underlying error with the captured stdout and stderr from the command that produced it.

func (*ErrWithCmdOutput) Error added in v0.28.0

func (e *ErrWithCmdOutput) Error() string

Jump to

Keyboard shortcuts

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