Documentation
¶
Index ¶
- func CommandName(command string) string
- func NewExitError(exitErr exec.ExitError, cmd string, stdOut string, stdErr string, ...) error
- func RedactSensitiveArgs(args []string, sensitiveDataMatch []string) []string
- func RedactSensitiveData(msg string) string
- func TestAbortSignalRetainsOutputError(t *testing.T)
- type CmdTree
- type CmdTreeOptions
- type CommandRunner
- type ExitError
- type RunArgs
- func (b RunArgs) AppendParams(params ...string) RunArgs
- func (b RunArgs) WithCwd(cwd string) RunArgs
- func (b RunArgs) WithDebugLogging(debug bool) RunArgs
- func (b RunArgs) WithEnv(env []string) RunArgs
- func (b RunArgs) WithInteractive(interactive bool) RunArgs
- func (b RunArgs) WithShell(useShell bool) RunArgs
- func (b RunArgs) WithStdErr(stdErr io.Writer) RunArgs
- func (b RunArgs) WithStdIn(stdIn io.Reader) RunArgs
- func (b RunArgs) WithStdOut(stdOut io.Writer) RunArgs
- type RunResult
- type RunnerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommandName ¶ added in v1.34.0
CommandName returns a safe, normalized command name for telemetry. It removes the path and executable extension and lowercases the result.
func NewExitError ¶
func RedactSensitiveArgs ¶
func RedactSensitiveData ¶
Types ¶
type CmdTree ¶
type CmdTree struct {
CmdTreeOptions
*exec.Cmd
// contains filtered or unexported fields
}
CmdTree represents an exec.Cmd. Non-interactive commands run inside their own process group, while interactive commands inherit the parent's group so they can use the same terminal.
type CmdTreeOptions ¶
type CmdTreeOptions struct {
Interactive bool
}
Settings to modify the way CmdTree is executed
type CommandRunner ¶
type CommandRunner interface {
Run(ctx context.Context, args RunArgs) (RunResult, error)
RunList(ctx context.Context, commands []string, args RunArgs) (RunResult, error)
ToolInPath(name string) error
}
CommandRunner exposes the contract for executing console/shell commands for the specified runArgs
func NewCommandRunner ¶
func NewCommandRunner(opt *RunnerOptions) CommandRunner
Creates a new default instance of the CommandRunner. Passing nil will use the default values for RunnerOptions.
These options will be used by default during interactive commands unless specifically overridden within the command run arguments.
type ExitError ¶
type ExitError struct {
// The path or name of the command being invoked.
Cmd string
// The exit code of the command.
ExitCode int
// contains filtered or unexported fields
}
ExitError is the error returned when a command unsuccessfully exits.
func (*ExitError) Error ¶
Error augments the underlying exec.ExitError's Error with the stdout and stderr output of the command, if available.
func (*ExitError) Interrupted ¶ added in v1.37.0
Interrupted reports whether the process exit represents a Ctrl+C interrupt.
type RunArgs ¶
type RunArgs struct {
Cmd string
Args []string
// Any string from SensitiveData will be redacted as *** if found in Args
SensitiveData []string
Cwd string
Env []string
// Stderr will receive a copy of the text written to Stderr by
// the command.
// NOTE: RunResult.Stderr will still contain stderr output.
Stderr io.Writer
// Enables debug logging.
DebugLogging *bool
// When set will run the command within a shell
UseShell bool
// When set will attach commands to std input/output
Interactive bool
// When set will call the command with the specified StdIn
StdIn io.Reader
// When set will call the command with the specified StdOut
StdOut io.Writer
}
RunArgs exposes the command, arguments and other options when running console/shell commands
func NewRunArgs ¶
NewRunArgs creates a new instance with the specified cmd and args
func NewRunArgsWithSensitiveData ¶
NewRunArgs creates a new instance with the specified cmd and args and a list of SensitiveData Use this constructor to protect known sensitive data from going to logs
func (RunArgs) AppendParams ¶
Appends additional command params
func (RunArgs) WithDebugLogging ¶
Updates whether or not debug output will be written to default logger
func (RunArgs) WithInteractive ¶
Updates whether or not this will be an interactive commands Interactive command sets stdin, stdout & stderr to the OS console/terminal
func (RunArgs) WithStdErr ¶
Updates the stderr writer that will be used while invoking the command
type RunResult ¶
type RunResult struct {
// The exit code of the command.
ExitCode int
// The stdout output captured from running the command.
Stdout string
// The stderr output captured from running the command.
Stderr string
}
RunResult is the result of running a command.
func NewRunResult ¶
type RunnerOptions ¶
type RunnerOptions struct {
// Stdin is the input stream. If nil, os.Stdin is used.
Stdin io.Reader
// Stdout is the output stream. If nil, os.Stdout is used.
Stdout io.Writer
// Stderr is the error stream. If nil, os.Stderr is used.
Stderr io.Writer
// Whether debug logging is enabled. False by default.
DebugLogging bool
}