@@ -43,16 +43,14 @@ var (
43
43
ErrFailedStarting = errors .New ("command failed starting" )
44
44
// ErrSignaled is returned by Wait() if a signal was sent to the command while running.
45
45
ErrSignaled = errors .New ("command execution signaled" )
46
- // ErrExecutionFailed is returned by Wait() when a command executes but returns a non-zero error
47
- // code.
46
+ // ErrExecutionFailed is returned by Wait() when a command executes but returns a non-zero error code.
48
47
ErrExecutionFailed = errors .New ("command returned a non-zero exit code" )
49
48
// ErrFailedSendingSignal may happen if sending a signal to an already terminated process.
50
49
ErrFailedSendingSignal = errors .New ("failed sending signal" )
51
50
52
51
// ErrExecAlreadyStarted is a system error normally indicating a bogus double call to Run().
53
52
ErrExecAlreadyStarted = errors .New ("command has already been started (double `Run`)" )
54
- // ErrExecNotStarted is a system error normally indicating that Wait() has been called without
55
- // first calling Run().
53
+ // ErrExecNotStarted is a system error normally indicating that Wait() has been called without first calling Run().
56
54
ErrExecNotStarted = errors .New ("command has not been started (call `Run` first)" )
57
55
// ErrExecAlreadyFinished is a system error indicating a double call to Wait().
58
56
ErrExecAlreadyFinished = errors .New ("command is already finished" )
@@ -75,7 +73,7 @@ type Result struct {
75
73
}
76
74
77
75
type execution struct {
78
- //nolint:containedctx
76
+ //nolint:containedctx // Is there a way around this?
79
77
context context.Context
80
78
cancel context.CancelFunc
81
79
command * exec.Cmd
@@ -138,27 +136,24 @@ func (gc *Command) Clone() *Command {
138
136
return com
139
137
}
140
138
141
- // WithPTY requests that the command be executed with a pty for std streams. Parameters allow
142
- // showing which streams
143
- // are to be tied to the pty.
139
+ // WithPTY requests that the command be executed with a pty for std streams.
140
+ // Parameters allow showing which streams are to be tied to the pty.
144
141
// This command has no effect if Run has already been called.
145
142
func (gc * Command ) WithPTY (stdin , stdout , stderr bool ) {
146
143
gc .ptyStdout = stdout
147
144
gc .ptyStderr = stderr
148
145
gc .ptyStdin = stdin
149
146
}
150
147
151
- // WithFeeder ensures that the provider function will be executed and its output fed to the command
152
- // stdin. WithFeeder, like Feed, can be used multiple times, and writes will be performed
153
- // sequentially, in order.
148
+ // WithFeeder ensures that the provider function will be executed and its output fed to the command stdin.
149
+ // WithFeeder, like Feed, can be used multiple times, and writes will be performed sequentially, in order.
154
150
// This command has no effect if Run has already been called.
155
151
func (gc * Command ) WithFeeder (writers ... func () io.Reader ) {
156
152
gc .writers = append (gc .writers , writers ... )
157
153
}
158
154
159
155
// Feed ensures that the provider reader will be copied on the command stdin.
160
- // Feed, like WithFeeder, can be used multiple times, and writes will be performed in sequentially,
161
- // in order.
156
+ // Feed, like WithFeeder, can be used multiple times, and writes will be performed in sequentially, in order.
162
157
// This command has no effect if Run has already been called.
163
158
func (gc * Command ) Feed (reader io.Reader ) {
164
159
gc .writers = append (gc .writers , func () io.Reader {
@@ -198,7 +193,6 @@ func (gc *Command) Run(parentCtx context.Context) error {
198
193
199
194
// Create a contextual command, set the logger
200
195
cmd = gc .buildCommand (ctx )
201
-
202
196
// Get a debug-logger from the context
203
197
var (
204
198
log logger.Logger
@@ -339,8 +333,7 @@ func (gc *Command) wrap() error {
339
333
err error
340
334
)
341
335
342
- // XXXgolang: this is troubling. cmd.ProcessState.ExitCode() is always fine, even if
343
- // cmd.ProcessState is nil.
336
+ // XXXgolang: this is troubling. cmd.ProcessState.ExitCode() is always fine, even if cmd.ProcessState is nil.
344
337
exitCode = cmd .ProcessState .ExitCode ()
345
338
346
339
if cmd .ProcessState != nil {
@@ -357,7 +350,7 @@ func (gc *Command) wrap() error {
357
350
}
358
351
}
359
352
360
- // Catch-up on the context
353
+ // Catch-up on the context.
361
354
switch ctx .Err () {
362
355
case context .DeadlineExceeded :
363
356
err = ErrTimeout
@@ -366,7 +359,7 @@ func (gc *Command) wrap() error {
366
359
default :
367
360
}
368
361
369
- // Stuff everything in Result and return err
362
+ // Stuff everything in Result and return err.
370
363
gc .result = & Result {
371
364
ExitCode : exitCode ,
372
365
Stdout : pipes .fromStdout ,
@@ -383,7 +376,7 @@ func (gc *Command) wrap() error {
383
376
}
384
377
385
378
func (gc * Command ) buildCommand (ctx context.Context ) * exec.Cmd {
386
- // Build arguments and binary
379
+ // Build arguments and binary.
387
380
args := gc .Args
388
381
if gc .PrependArgs != nil {
389
382
args = append (gc .PrependArgs , args ... )
@@ -459,12 +452,12 @@ func (gc *Command) buildCommand(ctx context.Context) *exec.Cmd {
459
452
cmd .Env = append (cmd .Env , k + "=" + v )
460
453
}
461
454
462
- // Attach platform ProcAttr and get optional custom cancellation routine
455
+ // Attach platform ProcAttr and get optional custom cancellation routine.
463
456
if cancellation := addAttr (cmd ); cancellation != nil {
464
457
cmd .Cancel = func () error {
465
458
gc .exec .log .Log ("command cancelled" )
466
459
467
- // Call the platform dependent cancellation routine
460
+ // Call the platform dependent cancellation routine.
468
461
return cancellation ()
469
462
}
470
463
}
0 commit comments