diff --git a/hcledit_test.go b/hcledit_test.go index ac571b0..3ff6cb3 100644 --- a/hcledit_test.go +++ b/hcledit_test.go @@ -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" { } diff --git a/internal/handler/block.go b/internal/handler/block.go index 690f13d..e8c2a7c 100644 --- a/internal/handler/block.go +++ b/internal/handler/block.go @@ -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, ), ) }