Skip to content

Commit 9104984

Browse files
authored
[hcledit/create] add new line before appending a block level comment (#105)
1 parent f186c5c commit 9104984

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

hcledit_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ block "label1" "label2" {
139139
opts: []hcledit.Option{hcledit.WithComment("test comment")},
140140
value: hcledit.BlockVal("label1", "label2"),
141141
want: `
142+
143+
// test comment
144+
block "label1" "label2" {
145+
}
146+
`,
147+
},
148+
149+
"Append block with comment": {
150+
input: `
151+
prev {}`,
152+
query: "block",
153+
opts: []hcledit.Option{hcledit.WithComment("test comment")},
154+
value: hcledit.BlockVal("label1", "label2"),
155+
want: `
156+
prev {}
142157
// test comment
143158
block "label1" "label2" {
144159
}

internal/handler/block.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (h *blockHandler) HandleBody(body *hclwrite.Body, name string, _ []string)
3030
body.AppendUnstructuredTokens(
3131
beforeTokens(
3232
fmt.Sprintf("// %s", strings.TrimSpace(strings.TrimPrefix(h.comment, "//"))),
33-
false,
33+
true,
3434
),
3535
)
3636
}

0 commit comments

Comments
 (0)