forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
organization.go
49 lines (40 loc) · 1.17 KB
/
organization.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
package requirements
import (
"github.com/cloudfoundry/cli/cf/api/organizations"
"github.com/cloudfoundry/cli/cf/models"
"github.com/cloudfoundry/cli/cf/terminal"
)
//go:generate counterfeiter -o fakes/fake_organization_requirement.go . OrganizationRequirement
type OrganizationRequirement interface {
Requirement
SetOrganizationName(string)
GetOrganization() models.Organization
}
type organizationApiRequirement struct {
name string
ui terminal.UI
orgRepo organizations.OrganizationRepository
org models.Organization
}
func NewOrganizationRequirement(name string, ui terminal.UI, sR organizations.OrganizationRepository) *organizationApiRequirement {
req := &organizationApiRequirement{}
req.name = name
req.ui = ui
req.orgRepo = sR
return req
}
func (req *organizationApiRequirement) Execute() (success bool) {
var apiErr error
req.org, apiErr = req.orgRepo.FindByName(req.name)
if apiErr != nil {
req.ui.Failed(apiErr.Error())
return false
}
return true
}
func (req *organizationApiRequirement) SetOrganizationName(name string) {
req.name = name
}
func (req *organizationApiRequirement) GetOrganization() models.Organization {
return req.org
}