Documentation
¶
Index ¶
- Constants
- Variables
- type Command
- func (c *Command) AddArgs(args ...string) *Command
- func (c *Command) AddEnvs(envs ...string) *Command
- func (c *Command) AddOptions(opts ...CommandOptions) *Command
- func (c *Command) Run() ([]byte, error)
- func (c *Command) RunInDir(dir string) ([]byte, error)
- func (c *Command) RunInDirPipeline(stdout, stderr io.Writer, dir string) error
- func (c *Command) RunInDirPipelineWithTimeout(timeout time.Duration, stdout, stderr io.Writer, dir string) (err error)
- func (c *Command) RunInDirWithOptions(dir string, opts ...RunInDirOptions) (err error)
- func (c *Command) RunInDirWithTimeout(timeout time.Duration, dir string) ([]byte, error)
- func (c *Command) RunWithTimeout(timeout time.Duration) ([]byte, error)
- func (c *Command) String() string
- type CommandOptions
- type RunInDirOptions
Constants ¶
const DefaultTimeout = time.Minute
DefaultTimeout is the default timeout duration for all commands.
Variables ¶
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 ¶
CICDCommand creates and returns a new Command with given arguments for "bash".
func NewCommand ¶
NewCommand creates and returns a new Command with given arguments for "git".
func SSHCommand ¶
SSHCommand creates prefix in ssh.
func (*Command) AddOptions ¶
func (c *Command) AddOptions(opts ...CommandOptions) *Command
AddOptions adds options to the command.
func (*Command) Run ¶
Run executes the command in working directory and default timeout duration. It returns stdout in string and error (combined with stderr).
func (*Command) RunInDir ¶
RunInDir executes the command in given directory and default timeout duration. It returns stdout and error (combined with stderr).
func (*Command) RunInDirPipeline ¶
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 ¶
RunInDirWithTimeout executes the command in given directory and timeout duration. It returns stdout in []byte and error (combined with stderr).
func (*Command) RunWithTimeout ¶
RunWithTimeout executes the command in working directory and given timeout duration. It returns stdout in string and error (combined with stderr).
type CommandOptions ¶
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.