mirror of
https://github.com/rancher/types.git
synced 2025-05-09 15:46:18 +00:00
Update generator
This commit is contained in:
parent
cca9708877
commit
1d1da066b5
51
main.go
51
main.go
@ -1,13 +1,56 @@
|
||||
//go:generate go run main.go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
_ "github.com/rancher/types/io.cattle.management/v1"
|
||||
"strings"
|
||||
|
||||
"github.com/rancher/norman/generator"
|
||||
"github.com/rancher/norman/types"
|
||||
clusterSchema "github.com/rancher/types/io.cattle.cluster/v1/schema"
|
||||
)
|
||||
|
||||
var VERSION = "v0.0.0-dev"
|
||||
var (
|
||||
basePackage = "github.com/rancher/types"
|
||||
baseCattle = "client"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("Nothing")
|
||||
generate(clusterSchema.Schemas)
|
||||
}
|
||||
|
||||
func generate(schemas *types.Schemas) {
|
||||
version := getVersion(schemas)
|
||||
groupParts := strings.Split(version.Group, ".")
|
||||
|
||||
cattleOutputPackage := path.Join(basePackage, baseCattle, groupParts[len(groupParts)-1], version.Version)
|
||||
k8sOutputPackage := path.Join(basePackage, version.Group, version.Version)
|
||||
|
||||
if err := generator.Generate(schemas, cattleOutputPackage, k8sOutputPackage); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func getVersion(schemas *types.Schemas) *types.APIVersion {
|
||||
var version types.APIVersion
|
||||
for _, schema := range schemas.Schemas() {
|
||||
if version.Group == "" {
|
||||
version = schema.Version
|
||||
continue
|
||||
}
|
||||
if version.Group != schema.Version.Group ||
|
||||
version.Version != schema.Version.Version {
|
||||
panic("schema set contains two APIVersions")
|
||||
}
|
||||
}
|
||||
|
||||
return &version
|
||||
}
|
||||
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user