From 3a3f71707bb95a3218f31bf0bc6ec80222dcff26 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Thu, 30 Aug 2018 12:25:59 -0700 Subject: [PATCH] command/format: Render unified diff for list and tuple value changes --- command/format/diff.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/command/format/diff.go b/command/format/diff.go index 7ac1703582..cb34dac0d4 100644 --- a/command/format/diff.go +++ b/command/format/diff.go @@ -534,9 +534,7 @@ func (p *blockBodyDiffPrinter) writeValueDiff(old, new cty.Value, indent int, pa // values are known and non-null. if old.IsKnown() && new.IsKnown() && !old.IsNull() && !new.IsNull() { switch { - // TODO: list diffs using longest-common-subsequence matching algorithm // TODO: object diffs that behave a bit like the map diffs, including if the two object types don't exactly match - // TODO: multi-line string diffs showing lines added/removed using longest-common-subsequence case ty == cty.String: // We have special behavior for both multi-line strings in general @@ -712,6 +710,25 @@ func (p *blockBodyDiffPrinter) writeValueDiff(old, new cty.Value, indent int, pa p.buf.WriteString("]") return + case ty.IsListType() || ty.IsTupleType(): + p.buf.WriteString("[") + if p.pathForcesNewResource(path) { + p.buf.WriteString(p.color.Color(forcesNewResourceCaption)) + } + p.buf.WriteString("\n") + + elemDiffs := ctySequenceDiff(old.AsValueSlice(), new.AsValueSlice()) + for _, elemDiff := range elemDiffs { + p.buf.WriteString(strings.Repeat(" ", indent+2)) + p.writeActionSymbol(elemDiff.Action) + p.writeValue(elemDiff.Value, elemDiff.Action, indent+4) + p.buf.WriteString(",\n") + } + + p.buf.WriteString(strings.Repeat(" ", indent)) + p.buf.WriteString("]") + return + case ty.IsMapType(): p.buf.WriteString("{") if p.pathForcesNewResource(path) {