hcl/printer: output an equal sign only if we had one originally

This commit is contained in:
Mitchell Hashimoto 2015-11-07 15:13:05 -08:00
parent 3bac6be959
commit b24dfd1bb1
6 changed files with 21 additions and 9 deletions

View File

@ -178,11 +178,13 @@ func (p *printer) objectItem(o *ast.ObjectItem) []byte {
buf.WriteByte(blank) buf.WriteByte(blank)
// reach end of key // reach end of key
if i == len(o.Keys)-1 && len(o.Keys) == 1 { if i == len(o.Keys)-1 {
if o.Assign.IsValid() && len(o.Keys) == 1 {
buf.WriteString("=") buf.WriteString("=")
buf.WriteByte(blank) buf.WriteByte(blank)
} }
} }
}
buf.Write(p.output(o.Val)) buf.Write(p.output(o.Val))

View File

@ -23,7 +23,7 @@ numbers = [1, 2] // another line here
variable = { variable = {
description = "bar" # another yooo description = "bar" # another yooo
foo = { foo {
# Nested standalone # Nested standalone
bar = "fatih" bar = "fatih"
@ -31,6 +31,6 @@ variable = {
} }
// lead comment // lead comment
foo = { foo {
bar = "fatih" // line comment 2 bar = "fatih" // line comment 2
} // line comment 3 } // line comment 3

View File

@ -1,4 +1,4 @@
aligned = { aligned {
# We have some aligned items below # We have some aligned items below
foo = "fatih" # yoo1 foo = "fatih" # yoo1
default = "bar" # yoo2 default = "bar" # yoo2

View File

@ -1,6 +1,6 @@
// A standalone comment // A standalone comment
aligned = { aligned {
# Standalone 1 # Standalone 1
a = "bar" # yoo1 a = "bar" # yoo1

View File

@ -26,10 +26,15 @@ resource aws_instance "web" {
"${aws_security_group.firewall.foo}", "${aws_security_group.firewall.foo}",
] ]
network_interface = { network_interface {
device_index = 0 device_index = 0
description = "Main network interface" description = "Main network interface"
} }
network_interface = {
device_index = 1
description = "Another network interface"
}
} }
resource "aws_instance" "db" { resource "aws_instance" "db" {

View File

@ -29,6 +29,11 @@ resource "aws_security_group" "firewall" {
device_index = 0 device_index = 0
description = "Main network interface" description = "Main network interface"
} }
network_interface = {
device_index = 1
description = "Another network interface"
}
} }
resource "aws_instance" "db" { resource "aws_instance" "db" {