github.com/go-tstr/tstr/dep/cmd
go get github.com/go-tstr/tstr/dep/cmd@v0.0.4
Constants
const (
ErrMissingCmd = strerr.Error("missing command")
ErrStartFailed = strerr.Error("failed to start command")
ErrReadyFailed = strerr.Error("failed to verify readiness")
ErrStopFailed = strerr.Error("command didn't stop successfully")
ErrOptApply = strerr.Error("failed apply Opt")
ErrNoMatchingLine = strerr.Error("no matching line found")
ErrNilCmdRegexp = strerr.Error("command has to be set before this option can be applied, check the order of options")
ErrPreCmdFailed = strerr.Error("pre command failed")
ErrBadRegexp = strerr.Error("bad regular expression for matching line")
ErrOutputPipe = strerr.Error("failed to aquire output pipe for command")
ErrBuildFailed = strerr.Error("failed to build go binary")
ErrCreateCoverDir = strerr.Error("failed create coverage dir")
)Functions
func MatchingLine
func MatchingLine(exp string, cmd *exec.Cmd) (func(*exec.Cmd) error, error)MatchLine waits for the command to output a line that matches the given regular expression.
func StopWithSignal
func StopWithSignal(s os.Signal) func(*exec.Cmd) errorStopWithSignal returns a stop function that sends the given signal to the command and waits for it to exit. This can be used with WithStopFn to stop the command with a specific signal.
Types
type Cmd
type Cmd struct {
// contains filtered or unexported fields
}func New
func New(opts ...Opt) *Cmdfunc (*Cmd) Ready
func (c *Cmd) Ready() errorfunc (*Cmd) Start
func (c *Cmd) Start() errorfunc (*Cmd) Stop
func (c *Cmd) Stop() errortype Opt
type Opt func(*Cmd) errorfunc WithCommand
func WithCommand(name string, args ...string) OptWithCommand creates a new command with the given name and arguments.
func WithDir
func WithDir(dir string) OptWithDir sets the working directory for the command.
func WithEnvAppend
func WithEnvAppend(env ...string) OptWithEnvAppend adds environment variables to commands current env. By default the command inherits the environment of the current process and setting this option will override it.
func WithEnvSet
func WithEnvSet(env ...string) OptWithEnvSet sets environment variables for the command. By default the command inherits the environment of the current process and setting this option will override it.
func WithExecCmd
func WithExecCmd(cmd *exec.Cmd) OptWithExecCmd allows user to construct the command with custom exec.Cmd.
func WithGoCode
func WithGoCode(modulePath, mainPkg string) OptWithGoCode builds the given Go projects and sets the main package as the command. By default the command is set to collect coverage data. Working directory for build command is set to modulePath which means that the mainPkg should be relative to it.
func WithGoCoverDir
func WithGoCoverDir(dir string) Optfunc WithPreCmd
func WithPreCmd(cmd *exec.Cmd) OptWithPreCmd runs the given command as part of the setup. This can be used to prepare the actual main command.
func WithReadyFn
func WithReadyFn(fn func(*exec.Cmd) error) OptWithReadyFn allows user to provide custom readiness function. Given fn should block until the command is ready.
func WithReadyHTTP
func WithReadyHTTP(url string) OptWithReadyHTTP sets the ready function to wait for url to return 200 OK.
func WithReadyTimeout
func WithReadyTimeout(d time.Duration) OptWithReadyTimeout overrides the default 30s timeout for the ready function.
func WithStopFn
func WithStopFn(fn func(*exec.Cmd) error) OptWithStopFn allows user to provide custom stop function.
func WithWaitExit
func WithWaitExit() OptWithWaitExit sets the ready and stop functions so that ready waits for the command to exit successfully and stop returns nil immediately. This is useful for commands that exit on their own and don't need to be stopped manually.
func WithWaitMatchingLine
func WithWaitMatchingLine(exp string) OptWithWaitMatchingLine sets the ready function so that it waits for the command to output a line that matches the given regular expression.