schema.go

 1package cmd
 2
 3import (
 4	"encoding/json"
 5	"fmt"
 6
 7	"github.com/charmbracelet/crush/internal/config"
 8	"github.com/invopop/jsonschema"
 9	"github.com/spf13/cobra"
10)
11
12var schemaCmd = &cobra.Command{
13	Use:    "schema",
14	Short:  "Generate JSON schema for configuration",
15	Long:   "Generate JSON schema for the crush configuration file",
16	Hidden: true,
17	RunE: func(cmd *cobra.Command, args []string) error {
18		reflector := jsonschema.Reflector{}
19		schema := reflector.Reflect(&config.Config{})
20
21		schemaJSON, err := json.MarshalIndent(schema, "", "  ")
22		if err != nil {
23			return fmt.Errorf("failed to marshal schema: %w", err)
24		}
25
26		fmt.Println(string(schemaJSON))
27		return nil
28	},
29}
30
31func init() {
32	rootCmd.AddCommand(schemaCmd)
33}