Documentation ¶
Overview ¶
The structs and functions in this file are almost exactly the same as the version in terratest (https://github.com/gruntwork-io/terratest/blob/37812f27666423c28ea22acb2bac2c80513dd318/modules/shell/output.go), except this version does not trim newlines from the streamed and captured texts. This ensures that the newlines reflect exactly how the underlying shell commands outputted. Otherwise, the newline is always stripped out on the last line, regardless of if the original command included it. That final terminating newline is more significant in production CLI usage vs testing purposes.
Index ¶
- Variables
- func CommandInstalled(command string) bool
- func CommandInstalledE(command string) error
- func FPromptUserForInput(out io.Writer, in io.Reader, prompt string, options *ShellOptions) (string, error)
- func FPromptUserForYesNo(out io.Writer, in io.Reader, prompt string, options *ShellOptions) (bool, error)
- func PromptUserForInput(prompt string, options *ShellOptions) (string, error)
- func PromptUserForPassword(prompt string, options *ShellOptions) (string, error)
- func PromptUserForYesNo(prompt string, options *ShellOptions) (bool, error)
- func RunShellCommand(options *ShellOptions, command string, args ...string) error
- func RunShellCommandAndGetAndStreamOutput(options *ShellOptions, command string, args ...string) (string, error)
- func RunShellCommandAndGetOutput(options *ShellOptions, command string, args ...string) (string, error)
- func RunShellCommandAndGetStdout(options *ShellOptions, command string, args ...string) (string, error)
- func RunShellCommandAndGetStdoutAndStreamOutput(options *ShellOptions, command string, args ...string) (string, error)
- func RunShellCommandWithInput(options *ShellOptions, inputString string, command string, args ...string) error
- type Output
- type ShellOptions
Constants ¶
This section is empty.
Variables ¶
var NonInteractivePasswordPrompt = fmt.Errorf("The non-interactive flag is set, so unable to prompt user for a password.")
Functions ¶
func CommandInstalled ¶
Return true if the OS has the given command installed
func CommandInstalledE ¶
CommandInstalledE returns an error if command is not installed
func FPromptUserForInput ¶
func FPromptUserForYesNo ¶
func PromptUserForInput ¶
func PromptUserForInput(prompt string, options *ShellOptions) (string, error)
Prompt the user for text in the CLI. Returns the text entered by the user.
func PromptUserForPassword ¶
func PromptUserForPassword(prompt string, options *ShellOptions) (string, error)
Prompt a user for a password or other sensitive info that should not be echoed back to stdout.
func PromptUserForYesNo ¶
func PromptUserForYesNo(prompt string, options *ShellOptions) (bool, error)
Prompt the user for a yes/no response and return true if they entered yes.
func RunShellCommand ¶
func RunShellCommand(options *ShellOptions, command string, args ...string) error
Run the specified shell command with the specified arguments. Connect the command's stdin, stdout, and stderr to the currently running app.
func RunShellCommandAndGetAndStreamOutput ¶
func RunShellCommandAndGetAndStreamOutput(options *ShellOptions, command string, args ...string) (string, error)
Run the specified shell command with the specified arguments. Return its interleaved stdout and stderr as a string and also stream stdout and stderr to the OS stdout/stderr
func RunShellCommandAndGetOutput ¶
func RunShellCommandAndGetOutput(options *ShellOptions, command string, args ...string) (string, error)
Run the specified shell command with the specified arguments. Return its stdout and stderr as a string
func RunShellCommandAndGetStdout ¶ added in v0.8.0
func RunShellCommandAndGetStdout(options *ShellOptions, command string, args ...string) (string, error)
Run the specified shell command with the specified arguments. Return its stdout as a string
func RunShellCommandAndGetStdoutAndStreamOutput ¶ added in v0.8.0
func RunShellCommandAndGetStdoutAndStreamOutput(options *ShellOptions, command string, args ...string) (string, error)
Run the specified shell command with the specified arguments. Return its stdout as a string and also stream stdout and stderr to the OS stdout/stderr
func RunShellCommandWithInput ¶ added in v0.10.1
func RunShellCommandWithInput(options *ShellOptions, inputString string, command string, args ...string) error
Like RunShellCommand, but feed the given content to the stdin of the process.
Types ¶
type Output ¶ added in v0.10.0
type Output struct {
// contains filtered or unexported fields
}
Output contains the output after runnig a command.
func RunShellCommandAndGetOutputStruct ¶ added in v0.10.0
func RunShellCommandAndGetOutputStruct(options *ShellOptions, command string, args ...string) (*Output, error)
Run the specified shell command with the specified arguments. Return its stdout, stderr, and interleaved output as separate strings in a struct.
func RunShellCommandAndGetOutputStructAndStreamOutput ¶ added in v0.10.0
func RunShellCommandAndGetOutputStructAndStreamOutput(options *ShellOptions, command string, args ...string) (*Output, error)
Run the specified shell command with the specified arguments. Return its stdout, stderr, and interleaved output as a struct and also stream stdout and stderr to the OS stdout/stderr
type ShellOptions ¶
type ShellOptions struct { NonInteractive bool Logger *logrus.Logger WorkingDir string SensitiveArgs bool // If true, will not log the arguments to the command Env map[string]string // Additional environment variables to set }
func NewShellOptions ¶
func NewShellOptions() *ShellOptions