Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify summary text. #2136

Merged
merged 2 commits into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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