mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
9f0b3f5609
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
46 lines
929 B
Go
46 lines
929 B
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
|
|
}
|
|
}
|
|
|
|
// WithExtraFile adds a file descriptor to the command
|
|
func WithExtraFile(f *os.File) CmdOp {
|
|
return func(c *Cmd) {
|
|
c.ExtraFiles = append(c.ExtraFiles, f)
|
|
}
|
|
}
|