From 8465d39a02f98ebef541e6bc9896890f3a2aa2ed Mon Sep 17 00:00:00 2001 From: joeduffy Date: Thu, 13 Jul 2017 09:56:49 -0700 Subject: [PATCH] Tidy up some planning/deployment messages --- cmd/lumi/deploy.go | 12 ++++++---- cmd/lumi/plan.go | 57 ++++++++++++++++++++++++++-------------------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/cmd/lumi/deploy.go b/cmd/lumi/deploy.go index 136462410..3b59a97e2 100644 --- a/cmd/lumi/deploy.go +++ b/cmd/lumi/deploy.go @@ -136,11 +136,15 @@ func deployLatest(cmd *cobra.Command, info *envCmdInfo, opts deployOptions) erro // Print a summary. var footer bytes.Buffer - if empty { - cmdutil.Diag().Infof(diag.Message("no resources need to be updated")) - } else { + if !empty { // 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", colors.SpecUnimportant, time.Since(start), colors.Reset)) } diff --git a/cmd/lumi/plan.go b/cmd/lumi/plan.go index 460c062fe..7bcc6e5eb 100644 --- a/cmd/lumi/plan.go +++ b/cmd/lumi/plan.go @@ -210,11 +210,15 @@ func printPlan(result *planResult, opts deployOptions) error { } // If we are doing an empty update, say so. - if empty { - cmdutil.Diag().Infof(diag.Message("no resources need to be updated")) - } else { + if !empty { // 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)) } 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 for _, c := range counts { total += c } - var planned string - if plan { - planned = "planned " - } - var colon string - if total != 0 { - colon = ":" - } - b.WriteString(fmt.Sprintf("%v total %v%v%v\n", total, planned, plural("change", total), colon)) + if total > 0 { + var kind string + if plan { + kind = "planned" + } else { + kind = "deployed" + } + b.WriteString(fmt.Sprintf("%vinfo%v: %v %v %v:\n", + colors.SpecInfo, colors.Reset, total, kind, plural("change", total))) - var planTo string - var pastTense string - if plan { - planTo = "to " - } else { - pastTense = "d" - } + var planTo string + var pastTense string + if plan { + planTo = "to " + } else { + pastTense = "d" + } - for _, op := range deploy.StepOps { - if c := counts[op]; c > 0 { - b.WriteString(fmt.Sprintf(" %v%v %v %v%v%v%v\n", - op.Prefix(), c, plural("resource", c), planTo, op, pastTense, colors.Reset)) + for _, op := range deploy.StepOps { + if c := counts[op]; c > 0 { + b.WriteString(fmt.Sprintf(" %v%v %v %v%v%v%v\n", + op.Prefix(), c, plural("resource", c), planTo, op, pastTense, colors.Reset)) + } } } + + return total } func plural(s string, c int) string {