Merge pull request #9448 from hashicorp/9440

make sure the no-op progress bar gets used for machine readable uis
This commit is contained in:
Megan Marsh 2020-06-18 11:05:34 -07:00 committed by GitHub
commit 87b6eb141a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View File

@ -170,11 +170,12 @@ func (c *BuildCommand) RunContext(buildCtx context.Context, cla *BuildArgs) int
for i := range builds {
ui := c.Ui
if cla.Color {
// 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,
}
if _, ok := c.Ui.(*packer.MachineReadableUi); !ok {
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

View File

@ -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.