shell

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: MIT Imports: 12 Imported by: 3

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

Constants

This section is empty.

Variables

View Source
var BRIGHT_GREEN = color.New(color.FgHiGreen, color.Bold)
View Source
var NonInteractivePasswordPrompt = fmt.Errorf("The non-interactive flag is set, so unable to prompt user for a password.")

Functions

func CommandInstalled

func CommandInstalled(command string) bool

Return true if the OS has the given command installed

func CommandInstalledE

func CommandInstalledE(command string) error

CommandInstalledE returns an error if command is not installed

func FPromptUserForInput

func FPromptUserForInput(out io.Writer, in io.Reader, prompt string, options *ShellOptions) (string, error)

func FPromptUserForYesNo

func FPromptUserForYesNo(out io.Writer, in io.Reader, prompt string, options *ShellOptions) (bool, error)

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

func (*Output) Combined added in v0.10.0

func (o *Output) Combined() string

func (*Output) Stderr added in v0.10.0

func (o *Output) Stderr() string

func (*Output) Stdout added in v0.10.0

func (o *Output) Stdout() string

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

Jump to

Keyboard shortcuts

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