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