Fix prefix bug in copier.

This commit is contained in:
monopole
2021-02-08 14:39:25 -08:00
parent 94d06e1e18
commit 1df430255a
5 changed files with 32 additions and 24 deletions

View File

@@ -32,7 +32,7 @@ func (c Copier) subPath() string {
return filepath.Join("internal", c.pgmName)
}
func (c Copier) print() {
func (c Copier) Print() {
fmt.Printf(" apiMachineryModule: %s\n", c.spec.Module)
fmt.Printf(" replacementPath: %s\n", c.replacementPath())
fmt.Printf(" goModCache: %s\n", c.goModCache)
@@ -44,14 +44,14 @@ func (c Copier) print() {
fmt.Printf(" pwd: %s\n", os.Getenv("PWD"))
}
func NewCopier(s *ModuleSpec) Copier {
func NewCopier(s *ModuleSpec, prefix string) Copier {
tmp := Copier{
spec: s,
pgmName: os.Getenv("GOPACKAGE"),
goModCache: RunGetOutputCommand("go", "env", "GOMODCACHE"),
}
goMod := RunGetOutputCommand("go", "env", "GOMOD")
topPackage := filepath.Join(goMod[:len(goMod)-len("go.mod")-1], "yaml")
topPackage := filepath.Join(goMod[:len(goMod)-len("go.mod")-1], prefix)
k := strings.Index(topPackage, sigsK8sIo)
if k < 1 {
log.Fatalf("cannot find %s in %s", sigsK8sIo, topPackage)

View File

@@ -34,11 +34,11 @@ import (
)
func main() {
if len(os.Args) < 2 {
log.Fatal("Need name of yaml file containing module specs.")
if len(os.Args) < 3 {
log.Fatal("Need name of yaml file containing module specs and prefix.")
}
spec := internal.ReadSpec(os.Args[1])
c := internal.NewCopier(spec)
c := internal.NewCopier(spec, os.Args[2])
internal.RunNoOutputCommand("go", "get", spec.Name())
for _, p := range spec.Packages {
for _, n := range p.Files {