From 42e98f15aeb61171ad9e54b722818fc4c693b761 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Wed, 17 Jun 2020 11:57:12 -0700 Subject: [PATCH] make sure the no-op progress bar gets used for machine readable uis --- command/build.go | 9 +++++---- packer/ui.go | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/command/build.go b/command/build.go index 8271f2ebb..d463489c9 100644 --- a/command/build.go +++ b/command/build.go @@ -170,11 +170,12 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int for i := range builds { ui := c.Ui if cla.Color { - ui = &packer.ColoredUi{ - Color: colors[i%len(colors)], - Ui: ui, - } + // Only set up UI colors if -machine-readable isn't set. if _, ok := c.Ui.(*packer.MachineReadableUi); !ok { + ui = &packer.ColoredUi{ + Color: colors[i%len(colors)], + Ui: ui, + } ui.Say(fmt.Sprintf("%s: output will be in this color.", builds[i].Name())) if i+1 == len(builds) { // Add a newline between the color output and the actual output diff --git a/packer/ui.go b/packer/ui.go index bbbf01d61..593c46e13 100644 --- a/packer/ui.go +++ b/packer/ui.go @@ -131,7 +131,6 @@ func (u *ColoredUi) supportsColors() bool { type TargetedUI struct { Target string Ui Ui - *uiProgressBar } var _ Ui = new(TargetedUI) @@ -172,6 +171,10 @@ func (u *TargetedUI) prefixLines(arrow bool, message string) string { return strings.TrimRightFunc(result.String(), unicode.IsSpace) } +func (u *TargetedUI) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser { + return u.Ui.TrackProgress(src, currentSize, totalSize, stream) +} + // The BasicUI is a UI that reads and writes from a standard Go reader // and writer. It is safe to be called from multiple goroutines. Machine // readable output is simply logged for this UI.