Skip to content
This repository has been archived by the owner on Nov 18, 2021. It is now read-only.

cmd/cue: generate Go code from CUE #6

Closed
mpvl opened this issue Jan 30, 2019 · 3 comments
Closed

cmd/cue: generate Go code from CUE #6

mpvl opened this issue Jan 30, 2019 · 3 comments
Labels
FeatureRequest New feature or request

Comments

@mpvl
Copy link
Contributor

mpvl commented Jan 30, 2019

Or really any programming language, but Go is a good first target.

  • Generate Go structs (with comments) from CUE definitions
  • Generate validation code given the CUE constraints defined on these definitions (well, its the same thing in CUE, but for Go it needs to be split out)
@mpvl mpvl changed the title Generate Go code from CUE cmd/cue: generate Go code from CUE Jan 30, 2019
@mpvl mpvl added the FeatureRequest New feature or request label Apr 8, 2019
@tredoe
Copy link

tredoe commented Sep 15, 2019

This would be a great feature.
At my case, I'm exporting the Cue file to Json, for then to use 'jsonutil' (https://github.com/bashtian/jsonutils) to generate the Go struct where I load the Json data.

Now, I'm using Cue to deal with configuration files and it's the best tool that I've tried. But I've in mind to use it at data validation.

Congratulations!

@mpvl
Copy link
Contributor Author

mpvl commented Sep 20, 2019

Thanks for your kind words.

Interesting, I expected the code generation aspect would be more desirable. So note that in the mean time there is https://godoc.org/cuelang.org/go/encoding/gocode, which gets you part of the way. But that assumes the schema are already defined.

Generating just the structs should be quite straightforward, though. That would also allow you to retain documentation. It would be implemented using the above-mentioned API. This could then be used to implement a command line feature in the cue tool.

@cueckoo
Copy link

cueckoo commented Jul 3, 2021

This issue has been migrated to cue-lang/cue#6.

For more details about CUE's migration to a new home, please see cue-lang/cue#1078.

@cueckoo cueckoo closed this as completed Jul 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants