mirror of https://github.com/databricks/cli.git
44 lines
1017 B
Go
44 lines
1017 B
Go
package bundle
|
|
|
|
import (
|
|
"encoding/json"
|
|
"reflect"
|
|
|
|
"github.com/databricks/cli/bundle/config"
|
|
"github.com/databricks/cli/bundle/schema"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newSchemaCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "schema",
|
|
Short: "Generate JSON Schema for bundle configuration",
|
|
}
|
|
var includeTags []string
|
|
cmd.Flags().StringSliceVar(&includeTags, "include-tags", []string{}, "Also include fields with these tags.")
|
|
|
|
cmd.RunE = func(cmd *cobra.Command, args []string) error {
|
|
// Load embedded schema descriptions.
|
|
docs, err := schema.LoadBundleDescriptions()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Generate the JSON schema from the bundle configuration struct in Go.
|
|
schema, err := schema.New(reflect.TypeOf(config.Root{}), docs, includeTags)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Print the JSON schema to stdout.
|
|
result, err := json.MarshalIndent(schema, "", " ")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cmd.OutOrStdout().Write(result)
|
|
return nil
|
|
}
|
|
|
|
return cmd
|
|
}
|