schema.go 644 B

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