feat: add schema command

We should probably serve this file in a short URL.
This commit is contained in:
Carlos Alexandro Becker
2025-07-28 21:39:10 -03:00
parent a9716e04ce
commit bef2ea1b25
3 changed files with 52 additions and 3 deletions

33
internal/cmd/schema.go Normal file
View File

@@ -0,0 +1,33 @@
package cmd
import (
"encoding/json"
"fmt"
"github.com/charmbracelet/crush/internal/config"
"github.com/invopop/jsonschema"
"github.com/spf13/cobra"
)
var schemaCmd = &cobra.Command{
Use: "schema",
Short: "Generate JSON schema for configuration",
Long: "Generate JSON schema for the crush configuration file",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
reflector := jsonschema.Reflector{}
schema := reflector.Reflect(&config.Config{})
schemaJSON, err := json.MarshalIndent(schema, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal schema: %w", err)
}
fmt.Println(string(schemaJSON))
return nil
},
}
func init() {
rootCmd.AddCommand(schemaCmd)
}