Making Creator use CmdCreatorFunc (which was added) to allow users more

control over cmd creation
This commit is contained in:
Dan Ballard 2019-08-09 18:58:25 -07:00 committed by Dan Ballard
parent 1c71414a61
commit 75338dbf32
1 changed files with 10 additions and 9 deletions

View File

@ -40,25 +40,26 @@ type Creator interface {
New(ctx context.Context, args ...string) (Process, error) New(ctx context.Context, args ...string) (Process, error)
} }
type exeProcessCreator struct { type CmdCreatorFunc func(ctx context.Context, args ...string) (*exec.Cmd, error)
exePath string
}
// NewCreator creates a Creator for external Tor process execution based on the // NewCreator creates a Creator for external Tor process execution based on the
// given exe path. // given exe path.
func NewCreator(exePath string) Creator { func NewCreator(exePath string) Creator {
return &exeProcessCreator{exePath} return CmdCreatorFunc(func(ctx context.Context, args ...string) (*exec.Cmd, error) {
cmd := exec.CommandContext(ctx, exePath, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd, nil
})
} }
type exeProcess struct { type exeProcess struct {
*exec.Cmd *exec.Cmd
} }
func (e *exeProcessCreator) New(ctx context.Context, args ...string) (Process, error) { func (c CmdCreatorFunc) New(ctx context.Context, args ...string) (Process, error) {
cmd := exec.CommandContext(ctx, e.exePath, args...) cmd, err := c(ctx, args...)
cmd.Stdout = os.Stdout return &exeProcess{cmd}, err
cmd.Stderr = os.Stderr
return &exeProcess{cmd}, nil
} }
// ErrControlConnUnsupported is returned by Process.EmbeddedControlConn when // ErrControlConnUnsupported is returned by Process.EmbeddedControlConn when