cmdrunner

package
v3.4.5 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: Apache-2.0 Imports: 9 Imported by: 107

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CLI

func CLI(c *Command) string

CLI returns the CLI string without the dir or env vars

func DefaultCommandRunner

func DefaultCommandRunner(c *Command) (string, error)

DefaultCommandRunner default runner if none is set

func DryRunCommandRunner

func DryRunCommandRunner(c *Command) (string, error)

DryRunCommandRunner output the commands to be run

func QuietCommandRunner

func QuietCommandRunner(c *Command) (string, error)

QuietCommandRunner uses debug level logging to output commands executed and results

Types

type Command

type Command struct {
	Errors             []error
	Dir                string
	Name               string
	Args               []string
	ExponentialBackOff *backoff.ExponentialBackOff
	Timeout            time.Duration
	Out                io.Writer
	Err                io.Writer
	In                 io.Reader
	Env                map[string]string
	// contains filtered or unexported fields
}

Command is a struct containing the details of an external command to be executed

func NewCommand

func NewCommand(dir string, name string, args ...string) *Command

NewCommand helper to create a new command

func (*Command) Attempts

func (c *Command) Attempts() int

Attempts The number of times the command has been executed

func (*Command) CLI

func (c *Command) CLI() string

CLI returns the command line without environment variables

func (*Command) CurrentArgs

func (c *Command) CurrentArgs() []string

CurrentArgs returns the current command arguments

func (*Command) CurrentDir

func (c *Command) CurrentDir() string

CurrentDir returns the current Dir

func (*Command) CurrentEnv

func (c *Command) CurrentEnv() map[string]string

CurrentEnv returns the current environment variables

func (*Command) CurrentName

func (c *Command) CurrentName() string

CurrentName returns the current name of the command

func (*Command) DidError

func (c *Command) DidError() bool

DidError returns a boolean if any error occurred in any execution of the command

func (*Command) DidFail

func (c *Command) DidFail() bool

DidFail returns a boolean if the command could not complete (errored on every attempt)

func (*Command) Error

func (c *Command) Error() error

Error returns the last error

func (*Command) Run

func (c *Command) Run() (string, error)

Run Execute the command and block waiting for return values

func (*Command) RunWithoutRetry

func (c *Command) RunWithoutRetry() (string, error)

RunWithoutRetry Execute the command without retrying on failure and block waiting for return values

func (*Command) SetArgs

func (c *Command) SetArgs(args []string)

SetArgs Setter method for Args to enable use of interface instead of Command struct

func (*Command) SetDir

func (c *Command) SetDir(dir string)

SetDir Setter method for Dir to enable use of interface instead of Command struct

func (*Command) SetEnv

func (c *Command) SetEnv(env map[string]string)

SetEnv Setter method for Env to enable use of interface instead of Command struct

func (*Command) SetEnvVariable

func (c *Command) SetEnvVariable(name string, value string)

SetEnvVariable sets an environment variable into the environment

func (*Command) SetExponentialBackOff

func (c *Command) SetExponentialBackOff(backoff *backoff.ExponentialBackOff)

SetExponentialBackOff Setter method for ExponentialBackOff to enable use of interface instead of Command struct

func (*Command) SetName

func (c *Command) SetName(name string)

SetName Setter method for Name to enable use of interface instead of Command struct

func (*Command) SetTimeout

func (c *Command) SetTimeout(timeout time.Duration)

SetTimeout Setter method for Timeout to enable use of interface instead of Command struct

func (*Command) String

func (c *Command) String() string

String returns the full string with env vars

type CommandError

type CommandError struct {
	Command Command
	Output  string
	// contains filtered or unexported fields
}

CommandError is the error object encapsulating an error from a Command

func (CommandError) Cause

func (c CommandError) Cause() error

func (CommandError) Error

func (c CommandError) Error() string

type CommandRunner

type CommandRunner func(*Command) (string, error)

CommandRunner represents a command runner so that it can be stubbed out for testing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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