review comments

This commit is contained in:
Megan Marsh 2020-09-23 11:33:51 -07:00
parent 7b1826e107
commit 15ee44e857
3 changed files with 8 additions and 16 deletions

View File

@ -196,7 +196,7 @@ func wrappedMain() int {
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stdout,
PB: &packer.UiProgressBar{},
PB: &packer.NoopProgressTracker{},
}
ui = basicUi
if !inPlugin {
@ -208,12 +208,11 @@ func wrappedMain() int {
}
if backgrounded {
fmt.Fprint(os.Stderr, "Running in background, not using a TTY\n")
basicUi.PB = &packer.NoopProgressTracker{}
} else if TTY, err := openTTY(); err != nil {
fmt.Fprintf(os.Stderr, "No tty available: %s\n", err)
basicUi.PB = &packer.NoopProgressTracker{}
} else {
basicUi.TTY = TTY
basicUi.PB = &packer.UiProgressBar{}
defer TTY.Close()
}
}

View File

@ -15,14 +15,8 @@ func ProgressBarConfig(bar *pb.ProgressBar, prefix string) {
bar.Prefix(prefix)
}
var defaultUiProgressBar = &UiProgressBar{}
// UiProgressBar is a self managed progress bar singleton.
// decorate your struct with a *UiProgressBar to
// give it TrackProgress capabilities.
// In TrackProgress if UiProgressBar is nil
// defaultUiProgressBar will be used as
// the progress bar.
// UiProgressBar is a progress bar compatible with go-getter used in our
// UI structs.
type UiProgressBar struct {
Noop bool
lock sync.Mutex
@ -30,10 +24,9 @@ type UiProgressBar struct {
pbs int
}
var noOpProgressBar *UiProgressBar = nil
func (p *UiProgressBar) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser {
if p == nil {
return defaultUiProgressBar.TrackProgress(src, currentSize, totalSize, stream)
}
if p.Noop {
return stream
}

View File

@ -49,7 +49,7 @@ func (tty *testTTY) ReadString() (string, error) {
func TestColoredUi(t *testing.T) {
bufferUi := testUi()
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, defaultUiProgressBar}
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, &UiProgressBar{}}
if !ui.supportsColors() {
t.Skip("skipping for ui without color support")
@ -81,7 +81,7 @@ func TestColoredUi(t *testing.T) {
func TestColoredUi_noColorEnv(t *testing.T) {
bufferUi := testUi()
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, defaultUiProgressBar}
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, &UiProgressBar{}}
// Set the env var to get rid of the color
oldenv := os.Getenv("PACKER_NO_COLOR")