forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
factory.go
173 lines (147 loc) · 4.98 KB
/
factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package requirements
import (
"code.cloudfoundry.org/cli/cf"
"code.cloudfoundry.org/cli/cf/api"
"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
. "code.cloudfoundry.org/cli/cf/i18n"
"github.com/blang/semver"
)
//go:generate counterfeiter . Factory
type Factory interface {
NewApplicationRequirement(name string) ApplicationRequirement
NewDEAApplicationRequirement(name string) DEAApplicationRequirement
NewDiegoApplicationRequirement(name string) DiegoApplicationRequirement
NewServiceInstanceRequirement(name string) ServiceInstanceRequirement
NewLoginRequirement() Requirement
NewRoutingAPIRequirement() Requirement
NewSpaceRequirement(name string) SpaceRequirement
NewTargetedSpaceRequirement() Requirement
NewTargetedOrgRequirement() TargetedOrgRequirement
NewOrganizationRequirement(name string) OrganizationRequirement
NewDomainRequirement(name string) DomainRequirement
NewUserRequirement(username string, wantGUID bool) UserRequirement
NewBuildpackRequirement(buildpack string) BuildpackRequirement
NewAPIEndpointRequirement() Requirement
NewMinAPIVersionRequirement(commandName string, requiredVersion semver.Version) Requirement
NewMaxAPIVersionRequirement(commandName string, maximumVersion semver.Version) Requirement
NewUsageRequirement(Usable, string, func() bool) Requirement
NewNumberArguments([]string, ...string) Requirement
}
type apiRequirementFactory struct {
config coreconfig.ReadWriter
repoLocator api.RepositoryLocator
}
func NewFactory(config coreconfig.ReadWriter, repoLocator api.RepositoryLocator) (factory apiRequirementFactory) {
return apiRequirementFactory{config, repoLocator}
}
func (f apiRequirementFactory) NewApplicationRequirement(name string) ApplicationRequirement {
return NewApplicationRequirement(
name,
f.repoLocator.GetApplicationRepository(),
)
}
func (f apiRequirementFactory) NewDEAApplicationRequirement(name string) DEAApplicationRequirement {
return NewDEAApplicationRequirement(
name,
f.repoLocator.GetApplicationRepository(),
)
}
func (f apiRequirementFactory) NewDiegoApplicationRequirement(name string) DiegoApplicationRequirement {
return NewDiegoApplicationRequirement(
name,
f.repoLocator.GetApplicationRepository(),
)
}
func (f apiRequirementFactory) NewServiceInstanceRequirement(name string) ServiceInstanceRequirement {
return NewServiceInstanceRequirement(
name,
f.repoLocator.GetServiceRepository(),
)
}
func (f apiRequirementFactory) NewLoginRequirement() Requirement {
return NewLoginRequirement(
f.config,
)
}
func (f apiRequirementFactory) NewRoutingAPIRequirement() Requirement {
req := Requirements{
f.NewMinAPIVersionRequirement(T("This command"), cf.TCPRoutingMinimumAPIVersion),
NewRoutingAPIRequirement(
f.config,
),
}
return req
}
func (f apiRequirementFactory) NewSpaceRequirement(name string) SpaceRequirement {
return NewSpaceRequirement(
name,
f.repoLocator.GetSpaceRepository(),
)
}
func (f apiRequirementFactory) NewTargetedSpaceRequirement() Requirement {
return NewTargetedSpaceRequirement(
f.config,
)
}
func (f apiRequirementFactory) NewTargetedOrgRequirement() TargetedOrgRequirement {
return NewTargetedOrgRequirement(
f.config,
)
}
func (f apiRequirementFactory) NewOrganizationRequirement(name string) OrganizationRequirement {
return NewOrganizationRequirement(
name,
f.repoLocator.GetOrganizationRepository(),
)
}
func (f apiRequirementFactory) NewDomainRequirement(name string) DomainRequirement {
return NewDomainRequirement(
name,
f.config,
f.repoLocator.GetDomainRepository(),
)
}
func (f apiRequirementFactory) NewUserRequirement(username string, wantGUID bool) UserRequirement {
return NewUserRequirement(
username,
f.repoLocator.GetUserRepository(),
wantGUID,
)
}
func (f apiRequirementFactory) NewBuildpackRequirement(buildpack string) BuildpackRequirement {
return NewBuildpackRequirement(
buildpack,
f.repoLocator.GetBuildpackRepository(),
)
}
func (f apiRequirementFactory) NewAPIEndpointRequirement() Requirement {
return NewAPIEndpointRequirement(
f.config,
)
}
func (f apiRequirementFactory) NewMinAPIVersionRequirement(commandName string, requiredVersion semver.Version) Requirement {
r := NewMinAPIVersionRequirement(
f.config,
commandName,
requiredVersion,
)
refresher := coreconfig.APIConfigRefresher{
Endpoint: f.config.APIEndpoint(),
EndpointRepo: f.repoLocator.GetEndpointRepository(),
Config: f.config,
}
return NewConfigRefreshingRequirement(r, refresher)
}
func (f apiRequirementFactory) NewMaxAPIVersionRequirement(commandName string, maximumVersion semver.Version) Requirement {
return NewMaxAPIVersionRequirement(
f.config,
commandName,
maximumVersion,
)
}
func (f apiRequirementFactory) NewUsageRequirement(cmd Usable, errorMessage string, pred func() bool) Requirement {
return NewUsageRequirement(cmd, errorMessage, pred)
}
func (f apiRequirementFactory) NewNumberArguments(passedArgs []string, expectedArgs ...string) Requirement {
return NewNumberArguments(passedArgs, expectedArgs)
}