Skip to content

Commit

Permalink
Simplify summary text. (#2136)
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Oct 31, 2018
1 parent 95a5ad4 commit 76d08f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
45 changes: 31 additions & 14 deletions pkg/backend/display/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
},
})
}
Expand Down

0 comments on commit 76d08f8

Please sign in to comment.