-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.go
38 lines (31 loc) · 1.38 KB
/
run.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Package run provides strategies for running command with a uniform interface.
// This packages requires github.com/go-cmd/cmd.
package run
import (
"errors"
"github.com/go-cmd/cmd"
)
var (
// ErrRunning is returned by a Runner if its Run method is called while still running.
ErrRunning = errors.New("already running")
// ErrStopped is returned by a Runner if its Stop method is called before Run finishes.
ErrStopped = errors.New("Stop called")
// ErrNonzeroExit is returned by a Runner if a Cmd returns a non-zero exit code.
ErrNonzeroExit = errors.New("non-zero exit")
)
// A Runner runs a list of commands. The interface is intentionally trivial
// because the real benefit lies in its implementation. For example, RunSync
// runs commands synchronously in the order given without retries or timeouts.
// Another implementation could implement a more complex strategy, for example,
// running commands in parallel. The implementation details are hidden from and
// irrelevant to the caller, which allows the caller to focus on running commands,
// not how they are ran.
type Runner interface {
Run([]cmd.Cmd) error
Stop() error
Status() ([]cmd.Status, int)
}
// A Factory makes a Runner for the given strategy. This is useful for testing:
// mock runners can be returned instead of real runners when testing to avoid
// running real commands.
type Factory func(strategy string) Runner