@@ -85,19 +85,19 @@ type Cmd struct {
8585 Stderr chan string
8686
8787 * 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 )
101101}
102102
103103var (
@@ -153,10 +153,10 @@ type Options struct {
153153 // streaming channels, else lines are dropped silently.
154154 Streaming bool
155155
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 )
160160}
161161
162162// 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 {
191191 c .stderrStream = NewOutputStream (c .Stderr )
192192 }
193193
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 {
197197 if f == nil {
198198 continue
199199 }
200- c .setCmdFuncs = append (c .setCmdFuncs , f )
200+ c .beforeExecFuncs = append (c .beforeExecFuncs , f )
201201 }
202202 }
203203
@@ -220,10 +220,10 @@ func (c *Cmd) Clone() *Cmd {
220220 clone .Dir = c .Dir
221221 clone .Env = c .Env
222222
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 ]
227227 }
228228 }
229229
@@ -417,7 +417,7 @@ func (c *Cmd) run(in io.Reader) {
417417 cmd .Dir = c .Dir
418418
419419 // Run all optional commands to customize underlying os/exe.Cmd.
420- for _ , f := range c .setCmdFuncs {
420+ for _ , f := range c .beforeExecFuncs {
421421 f (cmd )
422422 }
423423
0 commit comments