github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/targeted_organization.go (about)

     1  package requirements
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"code.cloudfoundry.org/cli/cf"
     8  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     9  	. "code.cloudfoundry.org/cli/cf/i18n"
    10  	"code.cloudfoundry.org/cli/cf/models"
    11  	"code.cloudfoundry.org/cli/cf/terminal"
    12  )
    13  
    14  //go:generate counterfeiter . TargetedOrgRequirement
    15  
    16  type TargetedOrgRequirement interface {
    17  	Requirement
    18  	GetOrganizationFields() models.OrganizationFields
    19  }
    20  
    21  type targetedOrgAPIRequirement struct {
    22  	config coreconfig.Reader
    23  }
    24  
    25  func NewTargetedOrgRequirement(config coreconfig.Reader) TargetedOrgRequirement {
    26  	return targetedOrgAPIRequirement{config}
    27  }
    28  
    29  func (req targetedOrgAPIRequirement) Execute() error {
    30  	if !req.config.HasOrganization() {
    31  		message := fmt.Sprintf(T("No org targeted, use '{{.Command}}' to target an org.", map[string]interface{}{"Command": terminal.CommandColor(cf.Name + " target -o ORG")}))
    32  		return errors.New(message)
    33  	}
    34  
    35  	return nil
    36  }
    37  
    38  func (req targetedOrgAPIRequirement) GetOrganizationFields() (org models.OrganizationFields) {
    39  	return req.config.OrganizationFields()
    40  }