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