mirror of
https://github.com/rancher/norman.git
synced 2025-09-17 15:49:53 +00:00
Updates to make rancher/types move work
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
@@ -367,10 +368,10 @@ func GenerateControllerForTypes(version *types.APIVersion, k8sOutputPackage stri
|
|||||||
return gofmt(baseDir, k8sOutputPackage)
|
return gofmt(baseDir, k8sOutputPackage)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Generate(schemas *types.Schemas, privateTypes map[string]bool, cattleOutputPackage, k8sOutputPackage string) error {
|
func Generate(schemas *types.Schemas, privateTypes map[string]bool, basePackage, outputDir, cattleOutputPackage, k8sOutputPackage string) error {
|
||||||
baseDir := args.DefaultSourceTree()
|
baseDir := args.DefaultSourceTree()
|
||||||
cattleDir := path.Join(baseDir, cattleOutputPackage)
|
cattleDir := path.Join(outputDir, cattleOutputPackage)
|
||||||
k8sDir := path.Join(baseDir, k8sOutputPackage)
|
k8sDir := path.Join(outputDir, k8sOutputPackage)
|
||||||
|
|
||||||
if cattleOutputPackage == "" {
|
if cattleOutputPackage == "" {
|
||||||
cattleDir = ""
|
cattleDir = ""
|
||||||
@@ -400,8 +401,7 @@ func Generate(schemas *types.Schemas, privateTypes map[string]bool, cattleOutput
|
|||||||
|
|
||||||
if privateType ||
|
if privateType ||
|
||||||
(contains(schema.CollectionMethods, http.MethodGet) &&
|
(contains(schema.CollectionMethods, http.MethodGet) &&
|
||||||
!strings.HasPrefix(schema.PkgName, "k8s.io") &&
|
strings.HasPrefix(schema.PkgName, basePackage)) {
|
||||||
!strings.Contains(schema.PkgName, "/vendor/")) {
|
|
||||||
controllers = append(controllers, schema)
|
controllers = append(controllers, schema)
|
||||||
if err := generateController(false, k8sDir, schema, schemas); err != nil {
|
if err := generateController(false, k8sDir, schema, schemas); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -423,7 +423,7 @@ func Generate(schemas *types.Schemas, privateTypes map[string]bool, cattleOutput
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(controllers) > 0 {
|
if len(controllers) > 0 {
|
||||||
if err := deepCopyGen(baseDir, k8sOutputPackage); err != nil {
|
if err := deepCopyGen(baseDir, filepath.Join(basePackage, k8sOutputPackage), filepath.Join(outputDir, k8sOutputPackage)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -439,12 +439,12 @@ func Generate(schemas *types.Schemas, privateTypes map[string]bool, cattleOutput
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gofmt(baseDir, k8sOutputPackage); err != nil {
|
if err := gofmt(baseDir, filepath.Join(outputDir, k8sOutputPackage)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if cattleOutputPackage != "" {
|
if cattleOutputPackage != "" {
|
||||||
return gofmt(baseDir, cattleOutputPackage)
|
return gofmt(baseDir, filepath.Join(outputDir, cattleOutputPackage))
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -487,7 +487,7 @@ func gofmt(workDir, pkg string) error {
|
|||||||
return cmd.Run()
|
return cmd.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
func deepCopyGen(workDir, pkg string) error {
|
func deepCopyGen(workDir, pkg, pkgPath string) error {
|
||||||
arguments := &args.GeneratorArgs{
|
arguments := &args.GeneratorArgs{
|
||||||
InputDirs: []string{pkg},
|
InputDirs: []string{pkg},
|
||||||
OutputBase: workDir,
|
OutputBase: workDir,
|
||||||
@@ -505,7 +505,7 @@ func deepCopyGen(workDir, pkg string) error {
|
|||||||
return generator.Packages{
|
return generator.Packages{
|
||||||
&generator.DefaultPackage{
|
&generator.DefaultPackage{
|
||||||
PackageName: packageParts[len(packageParts)-1],
|
PackageName: packageParts[len(packageParts)-1],
|
||||||
PackagePath: pkg,
|
PackagePath: pkgPath,
|
||||||
HeaderText: []byte{},
|
HeaderText: []byte{},
|
||||||
GeneratorFunc: func(c *generator.Context) []generator.Generator {
|
GeneratorFunc: func(c *generator.Context) []generator.Generator {
|
||||||
return []generator.Generator{
|
return []generator.Generator{
|
||||||
|
Reference in New Issue
Block a user