Skip to content

encoding/*: allow exporting comments #1180

@romange

Description

@romange

Is your feature request related to a problem? Please describe.
Sometimes 3rd party systems require annotating configurations via comments.
For example, cloud-init requires that its yaml files have a she-bang line like this:

#cloud-config
<some yaml stuff>
......

See here https://cloudinit.readthedocs.io/en/latest/topics/examples.html for more examples.

Describe the solution you'd like
File test.cue

//cloud-config
foo: "bar"

hello: {
        // occupy
        world: "from mars?"
}

when exported via command cue export --out yaml --preserve-comments test.cue should produce something like this:

# cloud-config
foo: bar
hello:
  # occupy
  world: from mars?

Describe alternatives you've considered
There is an easy workaround when wrapping cue-cmd via bash script. It's suboptimal but it's not a blocker.

Additional context
Bonus point: Some comments may be relevant to cue language itself thus we do not really want to export them.
It could be nice to have a convention to export whitelisted comments. For example, only comments starting from /// will be exported.

Metadata

Metadata

Assignees

Labels

FeatureRequestNew feature or requestNeedsDesignFunctionality seems desirable, but not sure how it should look like.

Projects

Status

Planned

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions