command/format: Render unified diff for list and tuple value changes

This commit is contained in:
Martin Atkins 2018-08-30 12:25:59 -07:00
parent 30a46ed8ed
commit a37d5268eb
1 changed files with 19 additions and 2 deletions

View File

@ -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) {