Skip to content

Commit 1fa2170

Browse files
authored
Merge pull request #3391 from yyy1000/fix-license
🐛: (go/v4) Scaffold no header when lincense is type none
2 parents 4a04609 + 8b81fd1 commit 1fa2170

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

pkg/plugins/golang/v4/scaffolds/init.go

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,33 @@ func (s *initScaffolder) Scaffold() error {
8181
machinery.WithConfig(s.config),
8282
)
8383

84-
bpFile := &hack.Boilerplate{
85-
License: s.license,
86-
Owner: s.owner,
87-
}
88-
bpFile.Path = s.boilerplatePath
89-
if err := scaffold.Execute(bpFile); err != nil {
90-
return err
91-
}
84+
if s.license != "none" {
85+
bpFile := &hack.Boilerplate{
86+
License: s.license,
87+
Owner: s.owner,
88+
}
89+
bpFile.Path = s.boilerplatePath
90+
if err := scaffold.Execute(bpFile); err != nil {
91+
return err
92+
}
9293

93-
boilerplate, err := afero.ReadFile(s.fs.FS, s.boilerplatePath)
94-
if err != nil {
95-
return err
94+
boilerplate, err := afero.ReadFile(s.fs.FS, s.boilerplatePath)
95+
if err != nil {
96+
return err
97+
}
98+
// Initialize the machinery.Scaffold that will write the files to disk
99+
scaffold = machinery.NewScaffold(s.fs,
100+
machinery.WithConfig(s.config),
101+
machinery.WithBoilerplate(string(boilerplate)),
102+
)
103+
} else {
104+
s.boilerplatePath = ""
105+
// Initialize the machinery.Scaffold without boilerplate
106+
scaffold = machinery.NewScaffold(s.fs,
107+
machinery.WithConfig(s.config),
108+
)
96109
}
97110

98-
// Initialize the machinery.Scaffold that will write the files to disk
99-
scaffold = machinery.NewScaffold(s.fs,
100-
machinery.WithConfig(s.config),
101-
machinery.WithBoilerplate(string(boilerplate)),
102-
)
103-
104111
// If the KustomizeV2 was used to do the scaffold then
105112
// we need to ensure that we use its supported Kustomize Version
106113
// in order to support it

pkg/plugins/golang/v4/scaffolds/internal/templates/hack/boilerplate.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ Copyright {{ .Year }}.
106106
{{ index .Licenses .License }}*/`
107107

108108
var knownLicenses = map[string]string{
109-
"apache2": apache2,
110-
"none": "",
109+
"apache2": apache2,
110+
"copyright": "",
111111
}
112112

113113
const apache2 = `

pkg/plugins/golang/v4/scaffolds/internal/templates/makefile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,11 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
110110
111111
.PHONY: generate
112112
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
113+
{{ if .BoilerplatePath -}}
113114
$(CONTROLLER_GEN) object:headerFile={{printf "%q" .BoilerplatePath}} paths="./..."
115+
{{- else -}}
116+
$(CONTROLLER_GEN) object paths="./..."
117+
{{- end }}
114118
115119
.PHONY: fmt
116120
fmt: ## Run go fmt against code.

0 commit comments

Comments
 (0)