command

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTimeout = time.Minute

DefaultTimeout is the default timeout duration for all commands.

Variables

View Source
var (
	ErrExecTimeout = errors.New("execution was timed out")
)

Functions

This section is empty.

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

Command contains the name, arguments and environment variables of a command.

func CICDCommand

func CICDCommand(args ...string) *Command

CICDCommand creates and returns a new Command with given arguments for "bash".

func NewCommand

func NewCommand(args ...string) *Command

NewCommand creates and returns a new Command with given arguments for "git".

func SSHCommand

func SSHCommand(sshkeypath string, args ...string) *Command

SSHCommand creates prefix in ssh.

func (*Command) AddArgs

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

AddArgs appends given arguments to the command.

func (*Command) AddEnvs

func (c *Command) AddEnvs(envs ...string) *Command

AddEnvs appends given environment variables to the command.

func (*Command) AddOptions

func (c *Command) AddOptions(opts ...CommandOptions) *Command

AddOptions adds options to the command.

func (*Command) Run

func (c *Command) Run() ([]byte, error)

Run executes the command in working directory and default timeout duration. It returns stdout in string and error (combined with stderr).

func (*Command) RunInDir

func (c *Command) RunInDir(dir string) ([]byte, error)

RunInDir executes the command in given directory and default timeout duration. It returns stdout and error (combined with stderr).

func (*Command) RunInDirPipeline

func (c *Command) RunInDirPipeline(stdout, stderr io.Writer, dir string) error

RunInDirPipeline executes the command in given directory and default timeout duration. It pipes stdout and stderr to supplied io.Writer.

func (*Command) RunInDirPipelineWithTimeout

func (c *Command) RunInDirPipelineWithTimeout(
	timeout time.Duration,
	stdout, stderr io.Writer,
	dir string,
) (err error)

RunInDirPipelineWithTimeout executes the command in given directory and timeout duration. It pipes stdout and stderr to supplied io.Writer. DefaultTimeout will be used if the timeout duration is less than time.Nanosecond (i.e. less than or equal to 0). It returns an ErrExecTimeout if the execution was timed out.

func (*Command) RunInDirWithOptions

func (c *Command) RunInDirWithOptions(dir string, opts ...RunInDirOptions) (err error)

RunInDirWithOptions executes the command in given directory and options. It pipes stdin from supplied io.Reader, and pipes stdout and stderr to supplied io.Writer. DefaultTimeout will be used if the timeout duration is less than time.Nanosecond (i.e. less than or equal to 0). It returns an ErrExecTimeout if the execution was timed out.

func (*Command) RunInDirWithTimeout

func (c *Command) RunInDirWithTimeout(timeout time.Duration, dir string) ([]byte, error)

RunInDirWithTimeout executes the command in given directory and timeout duration. It returns stdout in []byte and error (combined with stderr).

func (*Command) RunWithTimeout

func (c *Command) RunWithTimeout(timeout time.Duration) ([]byte, error)

RunWithTimeout executes the command in working directory and given timeout duration. It returns stdout in string and error (combined with stderr).

func (*Command) String

func (c *Command) String() string

String returns the string representation of the command.

type CommandOptions

type CommandOptions struct {
	Args []string
	Envs []string
}

CommandOptions contains options for running a command.

type RunInDirOptions

type RunInDirOptions struct {
	// Stdin is the input to the command.
	Stdin io.Reader
	// Stdout is the outputs from the command.
	Stdout io.Writer
	// Stderr is the error output from the command.
	Stderr io.Writer
	// Timeout is the duration to wait before timing out.
	Timeout time.Duration
}

RunInDirOptions contains options for running a command in a directory.

Jump to

Keyboard shortcuts

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