packer: no colored output if machine-readable [GH-684]

This commit is contained in:
Mitchell Hashimoto 2013-12-16 14:10:28 -08:00
parent a6d5ebaf5e
commit 18f3588f35
2 changed files with 12 additions and 0 deletions

View File

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

View File

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