command: warnings should not exit

also properly colorize error/warnings

depends on https://github.com/mitchellh/cli/pull/15
This commit is contained in:
Paul Hinze 2015-03-05 14:22:34 -06:00
parent 000238835c
commit 4fc5ebf47e
3 changed files with 15 additions and 6 deletions

View File

@ -14,6 +14,7 @@ type ColorizeUi struct {
OutputColor string
InfoColor string
ErrorColor string
WarnColor string
Ui cli.Ui
}
@ -33,6 +34,10 @@ func (u *ColorizeUi) Error(message string) {
u.Ui.Error(u.colorize(message, u.ErrorColor))
}
func (u *ColorizeUi) Warn(message string) {
u.Ui.Warn(u.colorize(message, u.WarnColor))
}
func (u *ColorizeUi) colorize(message string, color string) string {
if color == "" {
return message

View File

@ -33,9 +33,9 @@ func validateContext(ctx *terraform.Context, ui cli.Ui) bool {
"fix these before continuing.\n")
if len(ws) > 0 {
ui.Output("Warnings:\n")
ui.Warn("Warnings:\n")
for _, w := range ws {
ui.Output(fmt.Sprintf(" * %s", w))
ui.Warn(fmt.Sprintf(" * %s", w))
}
if len(es) > 0 {
@ -44,13 +44,16 @@ func validateContext(ctx *terraform.Context, ui cli.Ui) bool {
}
if len(es) > 0 {
ui.Output("Errors:\n")
ui.Error("Errors:\n")
for _, e := range es {
ui.Output(fmt.Sprintf(" * %s", e))
ui.Error(fmt.Sprintf(" * %s", e))
}
return false
} else {
ui.Warn(fmt.Sprintf("\n"+
"No errors found. Continuing with %d warning(s).\n", len(ws)))
return true
}
return false
}
return true

View File

@ -331,6 +331,7 @@ func (m *Meta) process(args []string, vars bool) []string {
Ui: &ColorizeUi{
Colorize: m.Colorize(),
ErrorColor: "[red]",
WarnColor: "[yellow]",
Ui: m.oldUi,
},
}