hashicorp / hashicorp/hcl

Can't find instructions for inline comments for hclwrite

Open
#459 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

Greetings,

Would not be surprised if this is me, but I am unable to figure out how to add an inline comment using the hclwrite. For example, I have the following code;
```
f := hclwrite.NewEmptyFile()
rootBody := f.Body()
rootBody.SetAttributeValue("name", cty.StringVal(config.Name))
rootBody.AppendNewline()
rootBody.SetAttributeValue("mode", cty.StringVal("router"))
rootBody.AppendNewline()
log.Printf("%s", f.Bytes())
```

Which will give me the following output;
```
name = "gagent.example.org"

mode = "router"
```

What I am trying to do is add a comment so the actual output would be something like the following;
```
name = "gagent.example.org"

/*
* There are three modes of operation;
* client == Clients read a local agent file and send it to a router
* router == Routers route agent files to workers for operation
* worker == Workers process agent files
*/
mode = "router"
```

Again, I would not be surprised if I am just missing something simple, but any help would be appreciated it.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue provides a Go example using hclwrite.NewEmptyFile and Body methods, but names no repository file or test. Start by checking the hclwrite API and existing documentation for comment support; done means documenting how to produce the requested block comment output, or clearly stating whether that output is supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.