@@ -281,27 +281,28 @@ func PrintableCommand(parts []string) string {
281
281
282
282
const (
283
283
Ignore = 0 // Redirect to null
284
- Show = 1 // Show on stdout/stderr as normal
285
- ShowIfVerbose = 2 // Show if verbose is set, Ignore otherwise
286
- Capture = 3 // Capture into buffer
284
+ Show = 1 // Capture and print the stream
285
+ ShowIfVerbose = 2 // Capture and print the stream only if verbose
286
+ Capture = 3 // Capture into buffer and don't print
287
+ Stream = 4 // Stream data as it comes in, no capture
287
288
)
288
289
289
290
func ExecCommand (ctx * types.Context , command * exec.Cmd , stdout int , stderr int ) ([]byte , []byte , error ) {
290
291
if ctx .Verbose {
291
292
ctx .GetLogger ().UnformattedFprintln (os .Stdout , PrintableCommand (command .Args ))
292
293
}
293
294
294
- if stdout == Capture {
295
+ if stdout != Stream {
295
296
buffer := & bytes.Buffer {}
296
297
command .Stdout = buffer
297
- } else if stdout == Show || stdout == ShowIfVerbose && ctx . Verbose {
298
+ } else {
298
299
command .Stdout = os .Stdout
299
300
}
300
301
301
- if stderr == Capture {
302
+ if stderr != Stream {
302
303
buffer := & bytes.Buffer {}
303
304
command .Stderr = buffer
304
- } else if stderr == Show || stderr == ShowIfVerbose && ctx . Verbose {
305
+ } else {
305
306
command .Stderr = os .Stderr
306
307
}
307
308
@@ -313,13 +314,22 @@ func ExecCommand(ctx *types.Context, command *exec.Cmd, stdout int, stderr int)
313
314
err = command .Wait ()
314
315
315
316
var outbytes , errbytes []byte
317
+ // this operation is a no-op in case of streaming
316
318
if buf , ok := command .Stdout .(* bytes.Buffer ); ok {
317
319
outbytes = buf .Bytes ()
318
320
}
319
321
if buf , ok := command .Stderr .(* bytes.Buffer ); ok {
320
322
errbytes = buf .Bytes ()
321
323
}
322
324
325
+ if stdout == Show || (stdout == ShowIfVerbose && ctx .Verbose ) {
326
+ ctx .GetLogger ().UnformattedWrite (os .Stdout , outbytes )
327
+ }
328
+
329
+ if stderr == Show || (stderr == ShowIfVerbose && ctx .Verbose ) {
330
+ ctx .GetLogger ().UnformattedWrite (os .Stderr , errbytes )
331
+ }
332
+
323
333
return outbytes , errbytes , i18n .WrapError (err )
324
334
}
325
335
0 commit comments