Skip to content

Commit

Permalink
[hcledit/create] add new line before appending a block level comment (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-ph authored Apr 24, 2024
1 parent f186c5c commit 9104984
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions hcledit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,21 @@ block "label1" "label2" {
opts: []hcledit.Option{hcledit.WithComment("test comment")},
value: hcledit.BlockVal("label1", "label2"),
want: `
// test comment
block "label1" "label2" {
}
`,
},

"Append block with comment": {
input: `
prev {}`,
query: "block",
opts: []hcledit.Option{hcledit.WithComment("test comment")},
value: hcledit.BlockVal("label1", "label2"),
want: `
prev {}
// test comment
block "label1" "label2" {
}
Expand Down
2 changes: 1 addition & 1 deletion internal/handler/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (h *blockHandler) HandleBody(body *hclwrite.Body, name string, _ []string)
body.AppendUnstructuredTokens(
beforeTokens(
fmt.Sprintf("// %s", strings.TrimSpace(strings.TrimPrefix(h.comment, "//"))),
false,
true,
),
)
}
Expand Down

0 comments on commit 9104984

Please sign in to comment.