github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/organization.go (about) 1 package requirements 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/api/organizations" 5 "code.cloudfoundry.org/cli/cf/models" 6 ) 7 8 //go:generate counterfeiter . OrganizationRequirement 9 10 type OrganizationRequirement interface { 11 Requirement 12 SetOrganizationName(string) 13 GetOrganization() models.Organization 14 } 15 16 type organizationAPIRequirement struct { 17 name string 18 orgRepo organizations.OrganizationRepository 19 org models.Organization 20 } 21 22 func NewOrganizationRequirement(name string, sR organizations.OrganizationRepository) *organizationAPIRequirement { 23 req := &organizationAPIRequirement{} 24 req.name = name 25 req.orgRepo = sR 26 return req 27 } 28 29 func (req *organizationAPIRequirement) Execute() error { 30 var apiErr error 31 req.org, apiErr = req.orgRepo.FindByName(req.name) 32 33 if apiErr != nil { 34 return apiErr 35 } 36 37 return nil 38 } 39 40 func (req *organizationAPIRequirement) SetOrganizationName(name string) { 41 req.name = name 42 } 43 44 func (req *organizationAPIRequirement) GetOrganization() models.Organization { 45 return req.org 46 }