diff --git a/cmd/limactl/genschema.go b/cmd/limactl/genschema.go index 09bec5e930f..6116b8c57a2 100644 --- a/cmd/limactl/genschema.go +++ b/cmd/limactl/genschema.go @@ -7,6 +7,7 @@ import ( "github.com/invopop/jsonschema" "github.com/lima-vm/lima/pkg/limayaml" "github.com/spf13/cobra" + "github.com/wk8/go-ordered-map/v2" ) func newGenSchemaCommand() *cobra.Command { @@ -20,6 +21,22 @@ func newGenSchemaCommand() *cobra.Command { return genschemaCommand } +func toAny(args []string) []any { + result := []any{nil} + for _, arg := range args { + result = append(result, arg) + } + return result +} + +func getProp(props *orderedmap.OrderedMap[string, *jsonschema.Schema], key string) *jsonschema.Schema { + value, ok := props.Get(key) + if !ok { + return nil + } + return value +} + func genschemaAction(cmd *cobra.Command, _ []string) error { schema := jsonschema.Reflect(&limayaml.LimaYAML{}) // allow Disk to be either string (name) or object (struct) @@ -28,6 +45,11 @@ func genschemaAction(cmd *cobra.Command, _ []string) error { {Type: "string"}, {Type: "object"}, } + properties := schema.Definitions["LimaYAML"].Properties + getProp(properties, "os").Enum = toAny(limayaml.OSTypes) + getProp(properties, "arch").Enum = toAny(limayaml.ArchTypes) + getProp(properties, "mountType").Enum = toAny(limayaml.MountTypes) + getProp(properties, "vmType").Enum = toAny(limayaml.VMTypes) j, err := json.MarshalIndent(schema, "", " ") if err != nil { return err diff --git a/pkg/limayaml/limayaml.go b/pkg/limayaml/limayaml.go index 89d72bf550e..2d1424a3e1b 100644 --- a/pkg/limayaml/limayaml.go +++ b/pkg/limayaml/limayaml.go @@ -46,7 +46,9 @@ type LimaYAML struct { type ( OS = string + OSType = OS Arch = string + ArchType = Arch MountType = string VMType = string ) @@ -71,6 +73,13 @@ const ( WSL2 VMType = "wsl2" ) +var ( + OSTypes = []OSType{LINUX} + ArchTypes = []ArchType{X8664, AARCH64, ARMV7L, RISCV64} + MountTypes = []MountType{REVSSHFS, NINEP, VIRTIOFS, WSLMount} + VMTypes = []VMType{QEMU, VZ, WSL2} +) + type Rosetta struct { Enabled *bool `yaml:"enabled" json:"enabled" jsonschema:"nullable"` BinFmt *bool `yaml:"binfmt" json:"binfmt" jsonschema:"nullable"`