File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package cmd
22
33import (
4+ "encoding/json"
45 "errors"
56 "fmt"
67 "os"
@@ -26,6 +27,7 @@ func registerPreviewCmd(rootCmd *cobra.Command) {
2627
2728 schemaCmd .AddCommand (schemaCompileCmd )
2829 schemaCompileCmd .Flags ().String ("out" , "" , "output filepath; omitting writes to stdout" )
30+ schemaCompileCmd .Flags ().Bool ("json" , false , "output schema as JSON" )
2931}
3032
3133var previewCmd = & cobra.Command {
@@ -105,6 +107,21 @@ func schemaCompileCmdFunc(cmd *cobra.Command, args []string) error {
105107 // Add a newline at the end for hygiene's sake
106108 terminated := generated + "\n "
107109
110+ if cobrautil .MustGetBool (cmd , "json" ) {
111+ output := struct {
112+ SchemaText string `json:"schemaText"`
113+ }{
114+ SchemaText : terminated ,
115+ }
116+
117+ jsonOutput , err := json .Marshal (output )
118+ if err != nil {
119+ return err
120+ }
121+
122+ terminated = string (jsonOutput )
123+ }
124+
108125 if outputFilepath == "" {
109126 // Print to stdout
110127 fmt .Print (terminated )
You can’t perform that action at this time.
0 commit comments