command

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

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

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

func New

func New(cmd string) *Command

New construct new command based on string

func NewWithVarArgs

func NewWithVarArgs(cmd ...string) *Command

NewWithVarArgs construct new command based on a string array

func (*Command) DidError

func (c *Command) DidError() bool

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

func (*Command) Error

func (c *Command) Error() error

Error returns the last error

func (*Command) InDir

func (c *Command) InDir(dir string) *Command

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

func (*Command) Run

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

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

func (*Command) RunWithContext

func (c *Command) RunWithContext(ctx *context.Context) (string, error)

RunWithContext private method executes the command and wait for the result

func (*Command) SanitisedArgs

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

SanitisedArgs sanitises any password arguments before printing the error string. The actual sensitive argument is still present in the Command object

func (Command) String

func (c Command) String() string

String method returns a string representation of the Command

func (*Command) WithArg

func (c *Command) WithArg(arg string) *Command

WithArg sets an argument into the args

func (*Command) WithArgs

func (c *Command) WithArgs(args ...string) *Command

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

func (*Command) WithEnv

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

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

func (*Command) WithEnvVariable

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

WithEnvVariable sets an environment variable into the environment

func (*Command) WithTimeout

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

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

type Error

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

Error is the error object encapsulating an error from a Command

func (Error) Error

func (c Error) Error() string

Jump to

Keyboard shortcuts

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