-
Notifications
You must be signed in to change notification settings - Fork 296
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
cmd/export: emit comments by default for yaml #1549
base: master
Are you sure you want to change the base?
Conversation
Closes cue-lang#1180 Signed-off-by: Felix Geisendörfer <[email protected]>
7d63a58
to
9b0de10
Compare
This looks fine in general to me (and welcome!), but one thought: |
@rogpeppe @felixge: I'm a bit ambivalent about what the default should be, but at the very least it should be consistent with the behavior for other formats. Since the default for Note that for For now, though, for consistency, it may be easiest to use An alternative thought would be to overload the "simplify" flag ( The advantage of such a flag is that it may be useful in general, while allowing us to punt for now on proper naming for the flag specific to comments. |
I'm not sure I'd support overloading |
@@ -2132,7 +2132,7 @@ func All() Option { | |||
|
|||
// Docs indicates whether docs should be included. | |||
func Docs(include bool) Option { | |||
return func(p *options) { p.docs = true } | |||
return func(p *options) { p.docs = include } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note: unrelated fix for a problem I noticed
Signed-off-by: Felix Geisendörfer <[email protected]>
d74f28d
to
7541204
Compare
Based on the discussion above, I just updated this PR to emit comments by default. I have not added One thing I'd like to note: I see two use cases for commenting
In the long run it would be nice to make cue aware of the different types of comments described above, but for now I think emitting all kinds of comments by default for YAML would be an improvement. |
Just stopping by to say I was just discussing this with a coworker and it'd a cool feature!
If it helps, our probable use case (just proposed Cue internally yesterday) is that we use it to validate some internal JSON files (probably will change them to YAML) that we then currently generate Terraform code off of. The JSON files contain various flags to determine say; you'd like to generate a service with a public load balancer vs a private one. The file abstracts away the specifics which is also handy given Cue lets us toggle different things on and off based on fields. For example, if In the case of comments, it would be nice to fully document the resulting YAML file so that users know what all of the possible inputs/options are when they go to update the generated templates. The general proposed flow is that we (ab?)use Cue by exporting a default config file via Historically, we've just had a JSON file with no consistency across older generated files and newer ones that have newly added features. Backporting Cue comments would be cool as well by rerunning Cue over them 🙂 Anyway, personally I don't mind if this is behind a flag or on by default but yeah, cool to see this PR! |
I'm sure this isn't the fault of this PR, but there's definitely a bit more work to do here.
when the above exported as YAML using the
|
Another place a comment is lost on export:
I also noticed that end-of-line comments are also lost on import, so the comment in the following YAML is lost:
|
One other thing perhaps worth mentioning (might not be fixable): say we import some YAML like this:
It imports to CUE like this:
and then when re-exported as YAML, it looks like this:
That is, what was originally intended as a comment on the entire list of items has turned into |
@rogpeppe great points. I'd argue whether a comment above a list belongs to the first item or the list is ambiguous. Not sure what the right solution is. Anyway, I think these edge cases are somewhat orthogonal to the preservation of comments in general (this PR). But if this can't be merged until the whole approach is sound, I'm okay with it. I just don't have time right now to contribute to the nuanced debate and implementation this will require :(. |
After chatting this through with @mpvl, I think that this PR is probably fine as is. There are some hard problems to solve to get comments on output really right (the general problem probably doesn't even have a "right" answer in fact), and this will be a good way forward. |
@rogpeppe awesome. I just tried to fix the failing tests for this PR, but I could use some help with updating the golden files, e.g. the stuff in Here is what I tried:
But unfortunately this only modified the github workflow files, no the the golden fixtures:
Please advise : ) |
Also interested in this feature, just wondering if anything I can do to help with merging this feature? |
Paging @rogpeppe for an update on this. |
In general, you can update all the generated and "golden" files (even inside txtar archives) via:
Hopefully that helps? There's also a minor conflict now, if you could rebase that would be helpful. |
I didn't get a response above so I'll take care of importing this to Gerrit while fixing the merge conflicts and the test files :) I'll keep Felix as the author of course. |
Importing this into Gerrit uncovered a bit of a design issue. See #1180 (comment); I will post updates on that thread from now on. Please direct any design discussion there as well. |
Closes #1180