shell

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 12 Imported by: 2

Documentation

Overview

Package shell contains helper functions for starting and interacting with subprocesses.

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

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

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.Entry
	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