-
Notifications
You must be signed in to change notification settings - Fork 929
/
factory.go
120 lines (104 loc) · 2.96 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
package requirements
import (
"github.com/cloudfoundry/cli/cf/api"
"github.com/cloudfoundry/cli/cf/configuration"
"github.com/cloudfoundry/cli/cf/terminal"
)
type Requirement interface {
Execute() (success bool)
}
type Factory interface {
NewApplicationRequirement(name string) ApplicationRequirement
NewServiceInstanceRequirement(name string) ServiceInstanceRequirement
NewLoginRequirement() Requirement
NewSpaceRequirement(name string) SpaceRequirement
NewTargetedSpaceRequirement() Requirement
NewTargetedOrgRequirement() TargetedOrgRequirement
NewOrganizationRequirement(name string) OrganizationRequirement
NewDomainRequirement(name string) DomainRequirement
NewUserRequirement(username string) UserRequirement
NewBuildpackRequirement(buildpack string) BuildpackRequirement
NewApiEndpointRequirement() Requirement
}
type apiRequirementFactory struct {
ui terminal.UI
config configuration.Reader
repoLocator api.RepositoryLocator
}
func NewFactory(ui terminal.UI, config configuration.Reader, repoLocator api.RepositoryLocator) (factory apiRequirementFactory) {
return apiRequirementFactory{ui, config, repoLocator}
}
func (f apiRequirementFactory) NewApplicationRequirement(name string) ApplicationRequirement {
return NewApplicationRequirement(
name,
f.ui,
f.repoLocator.GetApplicationRepository(),
)
}
func (f apiRequirementFactory) NewServiceInstanceRequirement(name string) ServiceInstanceRequirement {
return NewServiceInstanceRequirement(
name,
f.ui,
f.repoLocator.GetServiceRepository(),
)
}
func (f apiRequirementFactory) NewLoginRequirement() Requirement {
return NewLoginRequirement(
f.ui,
f.config,
)
}
func (f apiRequirementFactory) NewSpaceRequirement(name string) SpaceRequirement {
return NewSpaceRequirement(
name,
f.ui,
f.repoLocator.GetSpaceRepository(),
)
}
func (f apiRequirementFactory) NewTargetedSpaceRequirement() Requirement {
return NewTargetedSpaceRequirement(
f.ui,
f.config,
)
}
func (f apiRequirementFactory) NewTargetedOrgRequirement() TargetedOrgRequirement {
return NewTargetedOrgRequirement(
f.ui,
f.config,
)
}
func (f apiRequirementFactory) NewOrganizationRequirement(name string) OrganizationRequirement {
return NewOrganizationRequirement(
name,
f.ui,
f.repoLocator.GetOrganizationRepository(),
)
}
func (f apiRequirementFactory) NewDomainRequirement(name string) DomainRequirement {
return NewDomainRequirement(
name,
f.ui,
f.config,
f.repoLocator.GetDomainRepository(),
)
}
func (f apiRequirementFactory) NewUserRequirement(username string) UserRequirement {
return NewUserRequirement(
username,
f.ui,
f.repoLocator.GetUserRepository(),
)
}
func (f apiRequirementFactory) NewBuildpackRequirement(buildpack string) BuildpackRequirement {
return NewBuildpackRequirement(
buildpack,
f.ui,
f.repoLocator.GetBuildpackRepository(),
)
}
func (f apiRequirementFactory) NewApiEndpointRequirement() Requirement {
return NewApiEndpointRequirement(
f.ui,
f.config,
)
}