-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command to generate jsonschema for limayaml
Signed-off-by: Anders F Björklund <[email protected]>
- Loading branch information
1 parent
e53aea8
commit 541eb2d
Showing
6 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
_output/ | ||
_artifacts/ | ||
lima.REJECTED.yaml | ||
schema-limayaml.json | ||
.config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/invopop/jsonschema" | ||
"github.com/lima-vm/lima/pkg/limayaml" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newGenSchemaCommand() *cobra.Command { | ||
genschemaCommand := &cobra.Command{ | ||
Use: "generate-schema", | ||
Short: "Generate json-schema document", | ||
Args: WrapArgsError(cobra.NoArgs), | ||
RunE: genschemaAction, | ||
Hidden: true, | ||
} | ||
return genschemaCommand | ||
} | ||
|
||
func genschemaAction(cmd *cobra.Command, _ []string) error { | ||
schema := jsonschema.Reflect(&limayaml.LimaYAML{}) | ||
j, err := json.MarshalIndent(schema, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
_, err = fmt.Fprintln(cmd.OutOrStdout(), string(j)) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters