mirror of
https://github.com/hashicorp/packer.git
synced 2026-10-04 21:53:18 -04:00
packer: no colored output if machine-readable [GH-684]
This commit is contained in:
@@ -133,6 +133,13 @@ func wrappedMain() int {
|
||||
envConfig.Ui = &packer.MachineReadableUi{
|
||||
Writer: os.Stdout,
|
||||
}
|
||||
|
||||
// Set this so that we don't get colored output in our machine-
|
||||
// readable UI.
|
||||
if err := os.Setenv("PACKER_NO_COLOR", "1"); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Packer failed to initialize UI: %s\n", err)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
env, err := packer.NewEnvironment(envConfig)
|
||||
|
||||
@@ -110,6 +110,11 @@ func (u *ColoredUi) colorize(message string, color UiColor, bold bool) string {
|
||||
}
|
||||
|
||||
func (u *ColoredUi) supportsColors() bool {
|
||||
// Never use colors if we have this environmental variable
|
||||
if os.Getenv("PACKER_NO_COLOR") != "" {
|
||||
return false
|
||||
}
|
||||
|
||||
// For now, on non-Windows machine, just assume it does
|
||||
if runtime.GOOS != "windows" {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user