Documentation
¶
Index ¶
- func WithStandardStreams(c *Command)
- type Command
- func (c *Command) AddEnv(key string, value string)
- func (c *Command) Execute() error
- func (c *Command) Executed() bool
- func (c *Command) ExitCode() int
- func (c *Command) SetTimeout(timeout string) error
- func (c *Command) SetTimeoutMS(ms int)
- func (c *Command) Stderr() string
- func (c *Command) Stdout() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithStandardStreams ¶
func WithStandardStreams(c *Command)
WithStandardStreams creates a command which steams its output to the stderr and stdout streams of the operating system
Types ¶
type Command ¶
type Command struct {
Command string
Env []string
Dir string
Timeout time.Duration
StderrWriter io.Writer
StdoutWriter io.Writer
WorkingDir string
// contains filtered or unexported fields
}
Command represents a single command which can be executed
func NewCommand ¶
NewCommand creates a new command You can add option with variadic option argument
Example:
c := cmd.NewCommand("echo hello", function (c *Command) {
c.WorkingDir = "/tmp"
})
c.Execute()
or you can use existing options functions
c := cmd.NewCommand("echo hello", cmd.WithStandardStreams)
c.Execute()
func (*Command) AddEnv ¶
AddEnv adds an environment variable to the command If a variable gets passed like ${VAR_NAME} the env variable will be read out by the current shell
func (*Command) Execute ¶
Execute executes the command and writes the results into it's own instance The results can be received with the Stdout(), Stderr() and ExitCode() methods
func (*Command) SetTimeout ¶
SetTimeout sets the timeout given a time unit Example: SetTimeout("100s") sets the timeout to 100 seconds
func (*Command) SetTimeoutMS ¶
SetTimeoutMS sets the timeout in milliseconds