Documentation ¶
Overview ¶
Package exec provides helpers for setting execution options for commands
Index ¶
- Variables
- type Option
- func AllowWinStderr() Option
- func HideCommand() Option
- func HideOutput() Option
- func LogError(v bool) Option
- func Output(output *string) Option
- func Redact(rexp string) Option
- func RedactString(s ...string) Option
- func Sensitive() Option
- func Stdin(t string) Option
- func StreamOutput() Option
- func Sudo(h host) Option
- func Writer(w io.Writer) Option
- type Options
- func (o *Options) AddOutput(prefix, stdout, stderr string)
- func (o *Options) Command(cmd string) (string, error)
- func (o *Options) LogCmd(prefix, cmd string)
- func (o *Options) LogDebugf(s string, args ...any)
- func (o *Options) LogErrorf(s string, args ...any)
- func (o *Options) LogInfof(s string, args ...any)
- func (o *Options) LogStdin(prefix string)
- func (o *Options) Redact(s string) string
- type Waiter
Constants ¶
This section is empty.
Variables ¶
var ( ErrRemote = errors.New("remote exec error") // ErrRemote is returned when an action fails on remote host ErrSudo = errors.New("sudo error") // ErrSudo is returned when wrapping a command with sudo fails )
var ( // DisableRedact will make redact not redact anything DisableRedact = false // Confirm will make all command execs ask for confirmation - this is a simplistic way for auditing what will be executed Confirm = false // DebugFunc can be replaced to direct the output of exec logging into your own function (standard sprintf interface) DebugFunc = func(s string, args ...any) { log.Debugf(s, args...) } // InfoFunc can be replaced to direct the output of exec logging into your own function (standard sprintf interface) InfoFunc = func(s string, args ...any) { log.Infof(s, args...) } // ErrorFunc can be replaced to direct the output of exec logging into your own function (standard sprintf interface) ErrorFunc = func(s string, args ...any) { log.Errorf(s, args...) } // ConfirmFunc is called to ask for confirmation ConfirmFunc = func(s string) bool { fmt.Println(s) fmt.Print("Allow? [Y/n]: ") reader := bufio.NewReader(os.Stdin) text, _ := reader.ReadString('\n') text = strings.TrimSpace(text) return text == "" || text == "Y" || text == "y" } )
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Options)
Option is a functional option for the exec package
func AllowWinStderr ¶
func AllowWinStderr() Option
AllowWinStderr exec option allows command to output to stderr without failing
func HideCommand ¶
func HideCommand() Option
HideCommand exec option for hiding the command-string and stdin contents from the logs
func HideOutput ¶
func HideOutput() Option
HideOutput exec option for hiding the command output from logs
func LogError ¶ added in v0.17.2
LogError exec option for enabling or disabling live error logging during exec
func Redact ¶
Redact exec option for defining a redact regexp pattern that will be replaced with [REDACTED] in the logs
func RedactString ¶
RedactString exec option for defining one or more strings to replace with [REDACTED] in the log output
func Sensitive ¶
func Sensitive() Option
Sensitive exec option for disabling all logging of the command
func StreamOutput ¶
func StreamOutput() Option
StreamOutput exec option for sending the command output to info log
type Options ¶
type Options struct { Stdin string AllowWinStderr bool LogInfo bool LogDebug bool LogError bool LogCommand bool LogOutput bool StreamOutput bool Sudo bool RedactFunc func(string) string Output *string Writer io.Writer // contains filtered or unexported fields }
Options is a collection of exec options
func (*Options) Command ¶ added in v0.4.0
Command returns the command wrapped in a sudo if sudo is enabled or the original command