Tidy up some planning/deployment messages

This commit is contained in:
joeduffy 2017-07-13 09:56:49 -07:00
parent a70790b81a
commit 8465d39a02
2 changed files with 40 additions and 29 deletions

View file

@ -136,11 +136,15 @@ func deployLatest(cmd *cobra.Command, info *envCmdInfo, opts deployOptions) erro
// Print a summary. // Print a summary.
var footer bytes.Buffer var footer bytes.Buffer
if empty { if !empty {
cmdutil.Diag().Infof(diag.Message("no resources need to be updated"))
} else {
// Print out the total number of steps performed (and their kinds), the duration, and any summary info. // Print out the total number of steps performed (and their kinds), the duration, and any summary info.
printSummary(&footer, progress.Ops, false) if c := printSummary(&footer, progress.Ops, false); c == 0 {
empty = true
}
}
if empty {
cmdutil.Diag().Infof(diag.Message("no changes were made"))
} else {
footer.WriteString(fmt.Sprintf("%vDeployment duration: %v%v\n", footer.WriteString(fmt.Sprintf("%vDeployment duration: %v%v\n",
colors.SpecUnimportant, time.Since(start), colors.Reset)) colors.SpecUnimportant, time.Since(start), colors.Reset))
} }

View file

@ -210,11 +210,15 @@ func printPlan(result *planResult, opts deployOptions) error {
} }
// If we are doing an empty update, say so. // If we are doing an empty update, say so.
if empty { if !empty {
cmdutil.Diag().Infof(diag.Message("no resources need to be updated"))
} else {
// Print a summary of operation counts. // Print a summary of operation counts.
printSummary(&summary, counts, true) if c := printSummary(&summary, counts, true); c == 0 {
empty = true
}
}
if empty {
cmdutil.Diag().Infof(diag.Message("no changes are required"))
} else {
fmt.Print(colors.Colorize(&summary)) fmt.Print(colors.Colorize(&summary))
} }
return nil return nil
@ -256,36 +260,39 @@ func printConfig(b *bytes.Buffer, config resource.ConfigMap) {
} }
} }
func printSummary(b *bytes.Buffer, counts map[deploy.StepOp]int, plan bool) { func printSummary(b *bytes.Buffer, counts map[deploy.StepOp]int, plan bool) int {
total := 0 total := 0
for _, c := range counts { for _, c := range counts {
total += c total += c
} }
var planned string if total > 0 {
if plan { var kind string
planned = "planned " if plan {
} kind = "planned"
var colon string } else {
if total != 0 { kind = "deployed"
colon = ":" }
} b.WriteString(fmt.Sprintf("%vinfo%v: %v %v %v:\n",
b.WriteString(fmt.Sprintf("%v total %v%v%v\n", total, planned, plural("change", total), colon)) colors.SpecInfo, colors.Reset, total, kind, plural("change", total)))
var planTo string var planTo string
var pastTense string var pastTense string
if plan { if plan {
planTo = "to " planTo = "to "
} else { } else {
pastTense = "d" pastTense = "d"
} }
for _, op := range deploy.StepOps { for _, op := range deploy.StepOps {
if c := counts[op]; c > 0 { if c := counts[op]; c > 0 {
b.WriteString(fmt.Sprintf(" %v%v %v %v%v%v%v\n", b.WriteString(fmt.Sprintf(" %v%v %v %v%v%v%v\n",
op.Prefix(), c, plural("resource", c), planTo, op, pastTense, colors.Reset)) op.Prefix(), c, plural("resource", c), planTo, op, pastTense, colors.Reset))
}
} }
} }
return total
} }
func plural(s string, c int) string { func plural(s string, c int) string {