-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add schema cmds #37
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
c0609e8
465c8d4
01f1bd4
0da0024
19c851e
b1800f3
895280b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,71 @@ | ||||||||
| // Copyright 2024 Defense Unicorns | ||||||||
| // SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Defense-Unicorns-Commercial | ||||||||
|
|
||||||||
| package cmd | ||||||||
|
|
||||||||
| import ( | ||||||||
| "os" | ||||||||
|
|
||||||||
| helmSchema "github.com/defenseunicorns/uds-pk/src/schema" | ||||||||
| "github.com/spf13/cobra" | ||||||||
| "github.com/zarf-dev/zarf/src/pkg/message" | ||||||||
| ) | ||||||||
|
|
||||||||
| func schema() *cobra.Command { | ||||||||
| var schemaCmd = &cobra.Command{ | ||||||||
| Use: "schema", | ||||||||
| Aliases: []string{"s"}, | ||||||||
| Short: "Generate and check JSON schemas for values.yaml files.", | ||||||||
| } | ||||||||
|
|
||||||||
| return schemaCmd | ||||||||
|
|
||||||||
| } | ||||||||
|
Comment on lines
+22
to
+23
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| func generateSchemas() *cobra.Command { | ||||||||
| var baseDir string | ||||||||
|
|
||||||||
| generateSchemasCmd := &cobra.Command{ | ||||||||
| Use: "generate", | ||||||||
| Aliases: []string{"g"}, | ||||||||
| Short: "Generate JSON schemas for all values.yaml files in a base directory.", | ||||||||
| RunE: func(cmd *cobra.Command, args []string) error { | ||||||||
| if err := helmSchema.GenerateSchemas(baseDir); err != nil { | ||||||||
| message.WarnErr(err, "Failed to generate schemas") | ||||||||
| } | ||||||||
| return nil | ||||||||
| }, | ||||||||
| } | ||||||||
|
|
||||||||
| generateSchemasCmd.Flags().StringVarP(&baseDir, "base-dir", "b", "./charts", "Base directory to search for values.yaml files") | ||||||||
| return generateSchemasCmd | ||||||||
| } | ||||||||
|
|
||||||||
| func checkSchemas() *cobra.Command { | ||||||||
| var baseDir string | ||||||||
|
|
||||||||
| checkSchemasCmd := &cobra.Command{ | ||||||||
| Use: "validate", | ||||||||
| Aliases: []string{"v"}, | ||||||||
| Short: "Check if JSON schemas are up-to-date for all values.yaml files in a base directory.", | ||||||||
| RunE: func(cmd *cobra.Command, args []string) error { | ||||||||
| if err := helmSchema.ValidateSchemas(baseDir); err != nil { //TODO(ewyles) -- Renamed this to ValidateSchemas to match the cli verb name | ||||||||
| message.WarnErrf(err, "Failed to check schemas for %s: \n%s", baseDir, err.Error()) | ||||||||
| rootCmd.SilenceUsage = true | ||||||||
| os.Exit(1) | ||||||||
| } | ||||||||
| return nil | ||||||||
| }, | ||||||||
| } | ||||||||
|
|
||||||||
| checkSchemasCmd.Flags().StringVarP(&baseDir, "base-dir", "b", "./charts", "Base directory to search for values.yaml files") | ||||||||
| return checkSchemasCmd | ||||||||
| } | ||||||||
|
|
||||||||
| func init() { | ||||||||
| schemaCmd := schema() | ||||||||
|
|
||||||||
| schemaCmd.AddCommand(generateSchemas()) | ||||||||
| schemaCmd.AddCommand(checkSchemas()) | ||||||||
| rootCmd.AddCommand(schemaCmd) | ||||||||
|
Comment on lines
+68
to
+70
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should be consistent with the patterns we use for this (see how the other pk commands are)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure that's an easy enough change. |
||||||||
| } | ||||||||
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.
do we need this? The package is 7 yrs old
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.
We shouldnt
needit i'll look at finding a different way or library.