Skip to content

Commit

Permalink
Add quiet mode to progress printer
Browse files Browse the repository at this point in the history
Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
  • Loading branch information
ulyssessouza committed Mar 5, 2021
1 parent 7d2e300 commit aa91402
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions util/progress/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import (
"github.com/moby/buildkit/util/progress/progressui"
)

const (
PrinterModeAuto = "auto"
PrinterModeTty = "tty"
PrinterModeQuiet = "quiet"
)

type Printer struct {
status chan *client.SolveStatus
done <-chan struct{}
Expand All @@ -34,15 +40,25 @@ func NewPrinter(ctx context.Context, out console.File, mode string) *Printer {
done: doneCh,
}

if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == "auto" {
if v := os.Getenv("BUILDKIT_PROGRESS"); v != "" && mode == PrinterModeAuto {
mode = v
}

go func() {
var c console.Console
if cons, err := console.ConsoleFromFile(out); err == nil && (mode == "auto" || mode == "tty") {
c = cons
switch mode {
case PrinterModeQuiet:
devNull, err := os.Open(os.DevNull)
if err == nil {
out = devNull
}
fallthrough
case PrinterModeAuto, PrinterModeTty:
if cons, err := console.ConsoleFromFile(out); err == nil {
c = cons
}
}

// not using shared context to not disrupt display but let is finish reporting errors
pw.err = progressui.DisplaySolveStatus(ctx, "", c, out, statusCh)
close(doneCh)
Expand Down

0 comments on commit aa91402

Please sign in to comment.