Documentation
¶
Overview ¶
Package shell allows to run commands in a shell.
Index ¶
- func GetExitCodeForRunCommandError(err error) (int, error)
- func RunCommand(t testing.TestingT, command Command)deprecated
- func RunCommandAndGetOutput(t testing.TestingT, command Command) stringdeprecated
- func RunCommandAndGetOutputE(t testing.TestingT, command Command) (string, error)deprecated
- func RunCommandAndGetStdOut(t testing.TestingT, command Command) stringdeprecated
- func RunCommandAndGetStdOutE(t testing.TestingT, command Command) (string, error)deprecated
- func RunCommandAndGetStdOutErr(t testing.TestingT, command Command) (stdout string, stderr string)deprecated
- func RunCommandAndGetStdOutErrE(t testing.TestingT, command Command) (stdout string, stderr string, err error)deprecated
- func RunCommandContext(t testing.TestingT, ctx context.Context, command *Command)
- func RunCommandContextAndGetOutput(t testing.TestingT, ctx context.Context, command *Command) string
- func RunCommandContextAndGetOutputE(t testing.TestingT, ctx context.Context, command *Command) (string, error)
- func RunCommandContextAndGetStdOut(t testing.TestingT, ctx context.Context, command *Command) string
- func RunCommandContextAndGetStdOutE(t testing.TestingT, ctx context.Context, command *Command) (string, error)
- func RunCommandContextAndGetStdOutErr(t testing.TestingT, ctx context.Context, command *Command) (stdout string, stderr string)
- func RunCommandContextAndGetStdOutErrE(t testing.TestingT, ctx context.Context, command *Command) (stdout string, stderr string, err error)
- func RunCommandContextE(t testing.TestingT, ctx context.Context, command *Command) error
- func RunCommandE(t testing.TestingT, command Command) errordeprecated
- type Command
- type ErrWithCmdOutput
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetExitCodeForRunCommandError ¶
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 RunCommandAndGetOutput
deprecated
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
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
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
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
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
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
RunCommandContextE is like RunCommandE but includes a context.
func RunCommandE
deprecated
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