review comments
This commit is contained in:
parent
7b1826e107
commit
15ee44e857
5
main.go
5
main.go
|
@ -196,7 +196,7 @@ func wrappedMain() int {
|
||||||
Reader: os.Stdin,
|
Reader: os.Stdin,
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
ErrorWriter: os.Stdout,
|
ErrorWriter: os.Stdout,
|
||||||
PB: &packer.UiProgressBar{},
|
PB: &packer.NoopProgressTracker{},
|
||||||
}
|
}
|
||||||
ui = basicUi
|
ui = basicUi
|
||||||
if !inPlugin {
|
if !inPlugin {
|
||||||
|
@ -208,12 +208,11 @@ func wrappedMain() int {
|
||||||
}
|
}
|
||||||
if backgrounded {
|
if backgrounded {
|
||||||
fmt.Fprint(os.Stderr, "Running in background, not using a TTY\n")
|
fmt.Fprint(os.Stderr, "Running in background, not using a TTY\n")
|
||||||
basicUi.PB = &packer.NoopProgressTracker{}
|
|
||||||
} else if TTY, err := openTTY(); err != nil {
|
} else if TTY, err := openTTY(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "No tty available: %s\n", err)
|
fmt.Fprintf(os.Stderr, "No tty available: %s\n", err)
|
||||||
basicUi.PB = &packer.NoopProgressTracker{}
|
|
||||||
} else {
|
} else {
|
||||||
basicUi.TTY = TTY
|
basicUi.TTY = TTY
|
||||||
|
basicUi.PB = &packer.UiProgressBar{}
|
||||||
defer TTY.Close()
|
defer TTY.Close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,14 +15,8 @@ func ProgressBarConfig(bar *pb.ProgressBar, prefix string) {
|
||||||
bar.Prefix(prefix)
|
bar.Prefix(prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
var defaultUiProgressBar = &UiProgressBar{}
|
// UiProgressBar is a progress bar compatible with go-getter used in our
|
||||||
|
// UI structs.
|
||||||
// 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.
|
|
||||||
type UiProgressBar struct {
|
type UiProgressBar struct {
|
||||||
Noop bool
|
Noop bool
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
|
@ -30,10 +24,9 @@ type UiProgressBar struct {
|
||||||
pbs int
|
pbs int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var noOpProgressBar *UiProgressBar = nil
|
||||||
|
|
||||||
func (p *UiProgressBar) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser {
|
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 {
|
if p.Noop {
|
||||||
return stream
|
return stream
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ func (tty *testTTY) ReadString() (string, error) {
|
||||||
|
|
||||||
func TestColoredUi(t *testing.T) {
|
func TestColoredUi(t *testing.T) {
|
||||||
bufferUi := testUi()
|
bufferUi := testUi()
|
||||||
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, defaultUiProgressBar}
|
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, &UiProgressBar{}}
|
||||||
|
|
||||||
if !ui.supportsColors() {
|
if !ui.supportsColors() {
|
||||||
t.Skip("skipping for ui without color support")
|
t.Skip("skipping for ui without color support")
|
||||||
|
@ -81,7 +81,7 @@ func TestColoredUi(t *testing.T) {
|
||||||
|
|
||||||
func TestColoredUi_noColorEnv(t *testing.T) {
|
func TestColoredUi_noColorEnv(t *testing.T) {
|
||||||
bufferUi := testUi()
|
bufferUi := testUi()
|
||||||
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, defaultUiProgressBar}
|
ui := &ColoredUi{UiColorYellow, UiColorRed, bufferUi, &UiProgressBar{}}
|
||||||
|
|
||||||
// Set the env var to get rid of the color
|
// Set the env var to get rid of the color
|
||||||
oldenv := os.Getenv("PACKER_NO_COLOR")
|
oldenv := os.Getenv("PACKER_NO_COLOR")
|
||||||
|
|
Loading…
Reference in New Issue