@@ -16,6 +16,10 @@ limitations under the License.
16
16
17
17
package file
18
18
19
+ import (
20
+ "sigs.k8s.io/kubebuilder/pkg/model/resource"
21
+ )
22
+
19
23
// Input is the input for scaffolding a file
20
24
type Input struct {
21
25
// Path is the file to write
@@ -26,68 +30,98 @@ type Input struct {
26
30
27
31
// TemplateBody is the template body to execute
28
32
TemplateBody string
33
+ }
29
34
30
- // Boilerplate is the contents of a Boilerplate go header file
31
- Boilerplate string
35
+ // HasDomain allows the domain to be used on a template
36
+ type HasDomain interface {
37
+ // InjectDomain sets the template domain
38
+ InjectDomain (string )
39
+ }
32
40
41
+ // DomainMixin provides templates with a injectable domain field
42
+ type DomainMixin struct {
33
43
// Domain is the domain for the APIs
34
44
Domain string
45
+ }
35
46
36
- // Repo is the go project package
37
- Repo string
47
+ // InjectDomain implements HasDomain
48
+ func (m * DomainMixin ) InjectDomain (domain string ) {
49
+ if m .Domain == "" {
50
+ m .Domain = domain
51
+ }
52
+ }
38
53
39
- // MultiGroup is the multi-group boolean from the PROJECT file
40
- MultiGroup bool
54
+ // HasRepository allows the repository to be used on a template
55
+ type HasRepository interface {
56
+ // InjectRepository sets the template repository
57
+ InjectRepository (string )
41
58
}
42
59
43
- // Domain allows a domain to be set on an object
44
- type Domain interface {
45
- // SetDomain sets the domain
46
- SetDomain ( string )
60
+ // RepositoryMixin provides templates with a injectable repository field
61
+ type RepositoryMixin struct {
62
+ // Repo is the go project package path
63
+ Repo string
47
64
}
48
65
49
- // SetDomain sets the domain
50
- func (i * Input ) SetDomain ( d string ) {
51
- if i . Domain == "" {
52
- i . Domain = d
66
+ // InjectRepository implements HasRepository
67
+ func (m * RepositoryMixin ) InjectRepository ( repository string ) {
68
+ if m . Repo == "" {
69
+ m . Repo = repository
53
70
}
54
71
}
55
72
56
- // Repo allows a repo to be set on an object
57
- type Repo interface {
58
- // SetRepo sets the repo
59
- SetRepo ( string )
73
+ // HasMultiGroup allows the multi-group flag to be used on a template
74
+ type HasMultiGroup interface {
75
+ // InjectMultiGroup sets the template multi-group flag
76
+ InjectMultiGroup ( bool )
60
77
}
61
78
62
- // SetRepo sets the repo
63
- func (i * Input ) SetRepo (r string ) {
64
- if i .Repo == "" {
65
- i .Repo = r
66
- }
79
+ // MultiGroupMixin provides templates with a injectable multi-group flag field
80
+ type MultiGroupMixin struct {
81
+ // MultiGroup is the multi-group flag
82
+ MultiGroup bool
83
+ }
84
+
85
+ // InjectMultiGroup implements HasMultiGroup
86
+ func (m * MultiGroupMixin ) InjectMultiGroup (flag bool ) {
87
+ m .MultiGroup = flag
67
88
}
68
89
69
- // Boilerplate allows boilerplate text to be set on an object
70
- type Boilerplate interface {
71
- // SetBoilerplate sets the boilerplate text
72
- SetBoilerplate (string )
90
+ // HasBoilerplate allows a boilerplate to be used on a template
91
+ type HasBoilerplate interface {
92
+ // InjectBoilerplate sets the template boilerplate
93
+ InjectBoilerplate (string )
73
94
}
74
95
75
- // SetBoilerplate sets the boilerplate text
76
- func (i * Input ) SetBoilerplate (b string ) {
77
- if i .Boilerplate == "" {
78
- i .Boilerplate = b
96
+ // BoilerplateMixin provides templates with a injectable boilerplate field
97
+ type BoilerplateMixin struct {
98
+ // Boilerplate is the contents of a Boilerplate go header file
99
+ Boilerplate string
100
+ }
101
+
102
+ // InjectBoilerplate implements HasBoilerplate
103
+ func (m * BoilerplateMixin ) InjectBoilerplate (boilerplate string ) {
104
+ if m .Boilerplate == "" {
105
+ m .Boilerplate = boilerplate
79
106
}
80
107
}
81
108
82
- // MultiGroup allows the project version to be set on an object
83
- type MultiGroup interface {
84
- // SetVersion sets the project version
85
- SetMultiGroup ( value bool )
109
+ // HasResource allows a resource to be used on a template
110
+ type HasResource interface {
111
+ // InjectResource sets the template resource
112
+ InjectResource ( * resource. Resource )
86
113
}
87
114
88
- // SetVersion sets the MultiGroup value
89
- func (i * Input ) SetMultiGroup (v bool ) {
90
- i .MultiGroup = v
115
+ // ResourceMixin provides templates with a injectable resource field
116
+ type ResourceMixin struct {
117
+ Resource * resource.Resource
118
+ }
119
+
120
+ // InjectResource implements HasResource
121
+ func (m * ResourceMixin ) InjectResource (res * resource.Resource ) {
122
+ if m .Resource == nil {
123
+ m .Resource = res
124
+ }
91
125
}
92
126
93
127
// Template is a scaffoldable file template
0 commit comments