Simplify summary text. (#2136)

This commit is contained in:
CyrusNajmabadi 2018-10-30 21:57:38 -07:00 committed by GitHub
parent 95a5ad4a21
commit 76d08f8590
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 16 deletions

View file

@ -158,25 +158,18 @@ func renderStdoutColorEvent(payload engine.StdoutEventPayload, opts Options) str
func renderSummaryEvent(action apitype.UpdateKind, event engine.SummaryEventPayload, opts Options) string {
changes := event.ResourceChanges
changeCount := 0
for op, c := range changes {
if op != deploy.OpSame {
changeCount += c
}
}
out := &bytes.Buffer{}
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf("%sResources:%s\n", colors.SpecHeadline, colors.Reset)))
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf(" %s%d %s%s\n",
colors.Bold, changeCount, english.PluralWord(changeCount, "change", ""), colors.Reset)))
var planTo string
if event.IsPreview {
planTo = "to "
}
var changeCount = 0
var sameCount = changes[deploy.OpSame]
// Now summarize all of the changes; we print sames a little differently.
for _, op := range deploy.StepOps {
if op != deploy.OpSame {
@ -185,14 +178,38 @@ func renderSummaryEvent(action apitype.UpdateKind, event engine.SummaryEventPayl
if !event.IsPreview {
opDescription = op.PastTense()
}
fprintIgnoreError(out, opts.Color.Colorize(fmt.Sprintf(" %s%d %s%s%s\n",
op.Prefix(), c, planTo, opDescription, colors.Reset)))
changeCount++
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf(" %s%d %s%s%s\n", op.Prefix(), c, planTo, opDescription, colors.Reset)))
}
}
}
if c := changes[deploy.OpSame]; c > 0 {
fprintfIgnoreError(out, " %d unchanged\n", c)
summaryPieces := []string{}
if changeCount >= 2 {
// Only if we made multiple types of changes do we need to print out the total number of
// changes. i.e. we don't need "10 changes" and "+ 10 to create". We can just say "+ 10 to create"
summaryPieces = append(summaryPieces, fmt.Sprintf("%s%d %s%s",
colors.Bold, changeCount, english.PluralWord(changeCount, "change", ""), colors.Reset))
}
if sameCount != 0 {
summaryPieces = append(summaryPieces, fmt.Sprintf("%d unchanged", sameCount))
}
if len(summaryPieces) > 0 {
fprintfIgnoreError(out, " ")
for i, piece := range summaryPieces {
if i > 0 {
fprintfIgnoreError(out, ". ")
}
out.WriteString(opts.Color.Colorize(piece))
}
fprintfIgnoreError(out, "\n")
}
// For actual deploys, we print some additional summary information

View file

@ -209,8 +209,8 @@ func TestStackOutputsDisplayed(t *testing.T) {
output := stdout.String()
// ensure we get the outputs info both for the normal update, and for the no-change update.
assert.Contains(t, output, "Outputs:\n foo: 42\n xyz: \"ABC\"\n\nResources:\n 1 change")
assert.Contains(t, output, "Outputs:\n foo: 42\n xyz: \"ABC\"\n\nResources:\n 0 changes")
assert.Contains(t, output, "Outputs:\n foo: 42\n xyz: \"ABC\"\n\nResources:\n + 1 created")
assert.Contains(t, output, "Outputs:\n foo: 42\n xyz: \"ABC\"\n\nResources:\n 1 unchanged")
},
})
}