Skip to content
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

Feat: add vela def gen-cue command #5956

Merged
merged 5 commits into from
May 5, 2023
Merged

Conversation

iyear
Copy link
Contributor

@iyear iyear commented May 4, 2023

Description of your changes

πŸ€– Generated by Copilot at 8cffb50

Summary

πŸ“πŸŽ¨βœ¨

This pull request adds a new CLI subcommand vela def gen-cue to generate CUE schema from Go types for different kinds of definitions. It also adds a test case for the subcommand and improves the error message and the type representation in the cuegen package.

vela def gen-cue
From Go types to CUE schema
Autumn harvest time

Walkthrough

  • Add vela def gen-cue command to generate CUE schema from Go types (link, link, link)
  • Use cuegen and providergen packages to handle different types of definitions (link, link)
  • Support custom types and output path with flags and arguments (link)
  • Test the command with provider testdata and compare the output file with the expected file (link, link)
  • Change Type type and constants to string values for readability and consistency (link, link)
  • Import multierr package to handle multiple errors in a single value (link)

Part of #5364

Preview:

$ ./vela def gen-cue -h
Generate CUE schema from Go code.
* This command provide a way to generate CUE schema from Go code,
* Which can be used to keep consistency between Go code and CUE schema automatically.

Usage:
  vela def gen-cue [flags] SOURCE.go

Examples:
# Generate CUE schema for provider type
> vela def gen-cue -t provider /path/to/myprovider.go
# Generate CUE schema for provider type with custom types
> vela def gen-cue -t provider --types *k8s.io/apimachinery/pkg/apis/meta/v1/unstructured.Unstructured=ellipsis /path/to/myprovider.go
# Generate CUE schema for provider type with custom output path
> vela def gen-cue -t provider -o /path/to/myprovider.cue /path/to/myprovider.go


Flags:
  -h, --help                   help for gen-cue
      --nullable               Whether to generate null enum for pointer type
  -o, --output string          Output CUE file path, if not specified, the CUE file will be generated in the same directory
  -t, --type string            Type of the definition to generate. Valid types: [provider]
      --types stringToString   Special types to generate, format: <package+struct>=[any|ellipsis]. e.g. --types=*k8s.io/apimachinery/pkg/apis/meta/v1/unstructured.Unstructured=ellipsis (default [])

Global Flags:
  -y, --yes   Assume yes for all user prompts

I have:

  • Read and followed KubeVela's contribution process.
  • Related Docs updated properly. In a new feature or configuration option, an update to the documentation is necessary.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Special notes for your reviewer

@iyear
Copy link
Contributor Author

iyear commented May 4, 2023

/cc @FogDong @Somefive

For other enhancements such as dry-run, multi-files, output to stdout, etc. I will list in the tracking issue and implement in other PRs.

Signed-off-by: iyear <ljyngup@gmail.com>
@codecov
Copy link

codecov bot commented May 4, 2023

Codecov Report

Patch coverage has no change and project coverage change: +3.64 πŸŽ‰

Comparison is base (e828d3c) 56.88% compared to head (9af089b) 60.53%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5956      +/-   ##
==========================================
+ Coverage   56.88%   60.53%   +3.64%     
==========================================
  Files         219      224       +5     
  Lines       30973    31187     +214     
==========================================
+ Hits        17620    18880    +1260     
+ Misses      11710    10524    -1186     
- Partials     1643     1783     +140     
Flag Coverage Ξ”
core-unittests 55.80% <ΓΈ> (-0.08%) ⬇️
e2e-multicluster-test 24.69% <ΓΈ> (?)
e2etests 25.06% <ΓΈ> (-0.10%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 58 files with indirect coverage changes

β˜” View full report in Codecov by Sentry.
πŸ“’ Do you have feedback about the report comment? Let us know in this issue.

iyear added 4 commits May 4, 2023 21:53
Signed-off-by: iyear <ljyngup@gmail.com>
Signed-off-by: iyear <ljyngup@gmail.com>
Signed-off-by: iyear <ljyngup@gmail.com>
Signed-off-by: iyear <ljyngup@gmail.com>
@Somefive Somefive merged commit e675cda into kubevela:master May 5, 2023
22 checks passed
@iyear iyear deleted the feat/gen-cue-cli branch May 5, 2023 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants