@@ -85,19 +85,19 @@ type Cmd struct {
85
85
Stderr chan string
86
86
87
87
* sync.Mutex
88
- started bool // cmd.Start called, no error
89
- stopped bool // Stop called
90
- done bool // run() done
91
- final bool // status finalized in Status
92
- startTime time.Time // if started true
93
- stdoutBuf * OutputBuffer
94
- stderrBuf * OutputBuffer
95
- stdoutStream * OutputStream
96
- stderrStream * OutputStream
97
- status Status
98
- statusChan chan Status // nil until Start() called
99
- doneChan chan struct {} // closed when done running
100
- setCmdFuncs []func (cmd * exec.Cmd )
88
+ started bool // cmd.Start called, no error
89
+ stopped bool // Stop called
90
+ done bool // run() done
91
+ final bool // status finalized in Status
92
+ startTime time.Time // if started true
93
+ stdoutBuf * OutputBuffer
94
+ stderrBuf * OutputBuffer
95
+ stdoutStream * OutputStream
96
+ stderrStream * OutputStream
97
+ status Status
98
+ statusChan chan Status // nil until Start() called
99
+ doneChan chan struct {} // closed when done running
100
+ beforeExecFuncs []func (cmd * exec.Cmd )
101
101
}
102
102
103
103
var (
@@ -153,10 +153,10 @@ type Options struct {
153
153
// streaming channels, else lines are dropped silently.
154
154
Streaming bool
155
155
156
- // SetCmd is a list of callbacks to customize the underlying os/exec.Cmd.
157
- // For example, use it to set SysProcAttr. All callbacks are called once,
158
- // just before running the command .
159
- SetCmd []func (cmd * exec.Cmd )
156
+ // BeforeExec is a list of functions called immediately before starting
157
+ // the real command. These functions can be used to customize the underlying
158
+ // os/exec.Cmd. For example, to set SysProcAttr .
159
+ BeforeExec []func (cmd * exec.Cmd )
160
160
}
161
161
162
162
// NewCmdOptions creates a new Cmd with options. The command is not started
@@ -191,13 +191,13 @@ func NewCmdOptions(options Options, name string, args ...string) *Cmd {
191
191
c .stderrStream = NewOutputStream (c .Stderr )
192
192
}
193
193
194
- if len (options .SetCmd ) > 0 {
195
- c .setCmdFuncs = []func (cmd * exec.Cmd ){}
196
- for _ , f := range options .SetCmd {
194
+ if len (options .BeforeExec ) > 0 {
195
+ c .beforeExecFuncs = []func (cmd * exec.Cmd ){}
196
+ for _ , f := range options .BeforeExec {
197
197
if f == nil {
198
198
continue
199
199
}
200
- c .setCmdFuncs = append (c .setCmdFuncs , f )
200
+ c .beforeExecFuncs = append (c .beforeExecFuncs , f )
201
201
}
202
202
}
203
203
@@ -220,10 +220,10 @@ func (c *Cmd) Clone() *Cmd {
220
220
clone .Dir = c .Dir
221
221
clone .Env = c .Env
222
222
223
- if len (c .setCmdFuncs ) > 0 {
224
- clone .setCmdFuncs = make ([]func (cmd * exec.Cmd ), len (c .setCmdFuncs ))
225
- for i := range c .setCmdFuncs {
226
- clone .setCmdFuncs [i ] = c .setCmdFuncs [i ]
223
+ if len (c .beforeExecFuncs ) > 0 {
224
+ clone .beforeExecFuncs = make ([]func (cmd * exec.Cmd ), len (c .beforeExecFuncs ))
225
+ for i := range c .beforeExecFuncs {
226
+ clone .beforeExecFuncs [i ] = c .beforeExecFuncs [i ]
227
227
}
228
228
}
229
229
@@ -417,7 +417,7 @@ func (c *Cmd) run(in io.Reader) {
417
417
cmd .Dir = c .Dir
418
418
419
419
// Run all optional commands to customize underlying os/exe.Cmd.
420
- for _ , f := range c .setCmdFuncs {
420
+ for _ , f := range c .beforeExecFuncs {
421
421
f (cmd )
422
422
}
423
423
0 commit comments