
- go.mod: update dependencies and go version by
- Use Go1.20
- Fix couple of typos
- Added `WithStdout` and `WithStderr` helpers
- Moved `cmdOperators` handling from `RunCmd` to `StartCmd`
- Deprecate `assert.ErrorType`
- Remove outdated Dockerfile
- add godoc links
full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.4.0...v3.5.0
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit ce053a14aa
)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package icmd
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
"time"
|
|
)
|
|
|
|
// CmdOp is an operation which modified a Cmd structure used to execute commands
|
|
type CmdOp func(*Cmd)
|
|
|
|
// WithTimeout sets the timeout duration of the command
|
|
func WithTimeout(timeout time.Duration) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.Timeout = timeout
|
|
}
|
|
}
|
|
|
|
// WithEnv sets the environment variable of the command.
|
|
// Each arguments are in the form of KEY=VALUE
|
|
func WithEnv(env ...string) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.Env = env
|
|
}
|
|
}
|
|
|
|
// Dir sets the working directory of the command
|
|
func Dir(path string) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.Dir = path
|
|
}
|
|
}
|
|
|
|
// WithStdin sets the standard input of the command to the specified reader
|
|
func WithStdin(r io.Reader) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.Stdin = r
|
|
}
|
|
}
|
|
|
|
// WithStdout sets the standard output of the command to the specified writer
|
|
func WithStdout(w io.Writer) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.Stdout = w
|
|
}
|
|
}
|
|
|
|
// WithStderr sets the standard error of the command to the specified writer
|
|
func WithStderr(w io.Writer) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.Stderr = w
|
|
}
|
|
}
|
|
|
|
// WithExtraFile adds a file descriptor to the command
|
|
func WithExtraFile(f *os.File) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.ExtraFiles = append(c.ExtraFiles, f)
|
|
}
|
|
}
|