-
Notifications
You must be signed in to change notification settings - Fork 294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding/*: allow exporting comments #1180
Comments
This request seems reasonable to me for one main reason: we import comments, hence we should export them for round-trip-ness' sake if nothing else. FWIW it's not possible to control the export comments at all (unless I am missing something): neither through |
@myitcv I agree that this makes a lot of sense for the round-trip-ness. I also did not see any way to export comments. My example above was a modified Some thoughts after poking around
|
Makes a lot of sense. One alternative API is to export comments when used with |
Closes cue-lang#1180 Signed-off-by: Felix Geisendörfer <felix@felixge.de>
@felixge I was about to land your PR but first needed to fix a test case. In fixing that, I realised that perhaps this issue isn't as straightforward as it might seem. Here's the test case in question: https://review.gerrithub.io/c/cue-lang/cue/+/536265/2/cmd/cue/cmd/testdata/script/cmd_github.txt Note all the comments that have appeared in the YAML output for the test (a Github Actions file). Those comments aren't really relevant to the output file - they're really there to describe the schema of the actions file, not the final rendered result. In the final rendered result, I'd imagine that more repository-specific comments would be appropriate. Choosing a heuristic that decides which comments to be rendered in the final concrete output is tricky and will need some design input. Perhaps we might need to use an annotation hint; it could even be that it's not, after all, appropriate to include comments in rendered output. So I've left the Thanks for your input. Any further thoughts on this would be appreciated. |
@rogpeppe I agree that this feature would benefit from a sophisticated design. But in the short term, I don't see the harm of letting the user chose to either include comments or not when they invoke the |
So long as we're in a I realize that's a whole extra can of worms, but perhaps something like this could be made to work: struct: {
value: 17 @comment("from default")
} |
Hi Guys - Are there any ideas of how to proceed with this issue? It would be so nice to be able to export comments from a cue file. |
This might be slightly out of scope, but... To add a small comment, the OP brought up shebangs, and there's at least a few places where shebangs are used regardless of their validity in the normal export format. The one that comes to mind is Saltstack -- if you're using anything other than the Jinja|YAML renderer, you need a shebang at the top to designate it, eg, So maybe in addition to comments there might need to be some consideration or syntax for fixed annotations of whatever format in outputs? It may affect importing if you want to be able to round-trip data, too, though at least in the specific case of shebangs they're generally the first line so it's skippable... |
@jpluscplusm described my need for round-tripping YAML comments very concisely here:
Source: https://cuelang.slack.com/archives/CLT4FD7KP/p1694007965956239 |
For completeness, I will just mention that this paragraph was written and posted in the context of me role-playing as David, projecting my impression of their underlying, real-world requirements. I wasn't expressing what I needed, personally! :-) |
I began importing #1549 into Gerrit in separate commits - first testdata files, then the Docs API fix that Felix spotted, and then after would come the enabling of comments when encoding YAML. See https://review.gerrithub.io/c/cue-lang/cue/+/1199690. The Docs change uncovered a bit of a hidden problem: we never intended for It's also reasonable for a user to want to either export with or without comments, so we should support both modes - this would require a new flag, at least to enable or disable the inclusion of doc comments. This would also require threading this option through the Moreover, @rogpeppe and @mpvl argue that a boolean flag and option might not be enough. If CUE values unify concrete data with schemas, for example, they might both have doc comments. In some cases the user might want to output the comments from just the data, or from just the schema, or both combined. So perhaps a flag where one can do I will continue with this work step by step, but because we want to add the flag before "fixing" I will use this issue to track the ability to enable exporting comments via |
Much like encoding_empty.txtar, this is a high-level test for cmd/cue's ability to export CUE comments in different encodings, including to CUE. For #1180. For #3342. Signed-off-by: Daniel Martí <mvdan@mvdan.cc> Change-Id: I306c16d590b9c1faa45f8e083d094838cf9635ed Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199689 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Paul Jolly <paul@myitcv.io> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Hey @mvdan , my team can really use this feature in our project. Do we expect this to be available any time soon? Thanks! |
@KeranYang after getting TOML to a working state and other work, this is back near the top of my TODO list. I can't promise any particular timeline but I hope to make progress here in the coming weeks. |
Thank you very much @mvdan . Looking forward to it. |
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:
See here https://cloudinit.readthedocs.io/en/latest/topics/examples.html for more examples.
Describe the solution you'd like
File
test.cue
when exported via command
cue export --out yaml --preserve-comments test.cue
should produce something like this: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.The text was updated successfully, but these errors were encountered: