Merge pull request #7133 from hashicorp/b-output-empty-list-format

core: Format empty lists and maps in output
This commit is contained in:
James Nugent 2016-06-12 10:59:45 +01:00 committed by GitHub
commit 8d11e4dd8f
1 changed files with 11 additions and 2 deletions

View File

@ -148,6 +148,7 @@ func formatListOutput(indent, outputName string, outputList []interface{}) strin
keyIndent := "" keyIndent := ""
outputBuf := new(bytes.Buffer) outputBuf := new(bytes.Buffer)
if outputName != "" { if outputName != "" {
outputBuf.WriteString(fmt.Sprintf("%s%s = [", indent, outputName)) outputBuf.WriteString(fmt.Sprintf("%s%s = [", indent, outputName))
keyIndent = " " keyIndent = " "
@ -158,7 +159,11 @@ func formatListOutput(indent, outputName string, outputList []interface{}) strin
} }
if outputName != "" { if outputName != "" {
outputBuf.WriteString(fmt.Sprintf("\n%s]", indent)) if len(outputList) > 0 {
outputBuf.WriteString(fmt.Sprintf("\n%s]", indent))
} else {
outputBuf.WriteString("]")
}
} }
return strings.TrimPrefix(outputBuf.String(), "\n") return strings.TrimPrefix(outputBuf.String(), "\n")
@ -185,7 +190,11 @@ func formatMapOutput(indent, outputName string, outputMap map[string]interface{}
} }
if outputName != "" { if outputName != "" {
outputBuf.WriteString(fmt.Sprintf("\n%s}", indent)) if len(outputMap) > 0 {
outputBuf.WriteString(fmt.Sprintf("\n%s}", indent))
} else {
outputBuf.WriteString("}")
}
} }
return strings.TrimPrefix(outputBuf.String(), "\n") return strings.TrimPrefix(outputBuf.String(), "\n")