github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/cf/requirements/targeted_space.go (about)

     1  package requirements
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"errors"
     7  
     8  	"code.cloudfoundry.org/cli/cf"
     9  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
    10  	. "code.cloudfoundry.org/cli/cf/i18n"
    11  	"code.cloudfoundry.org/cli/cf/terminal"
    12  )
    13  
    14  type TargetedSpaceRequirement struct {
    15  	config coreconfig.Reader
    16  }
    17  
    18  func NewTargetedSpaceRequirement(config coreconfig.Reader) TargetedSpaceRequirement {
    19  	return TargetedSpaceRequirement{config}
    20  }
    21  
    22  func (req TargetedSpaceRequirement) Execute() error {
    23  	if !req.config.HasOrganization() {
    24  		message := fmt.Sprintf(T("No org and space targeted, use '{{.Command}}' to target an org and space", map[string]interface{}{"Command": terminal.CommandColor(cf.Name + " target -o ORG -s SPACE")}))
    25  		return errors.New(message)
    26  	}
    27  
    28  	if !req.config.HasSpace() {
    29  		message := fmt.Sprintf(T("No space targeted, use '{{.Command}}' to target a space.", map[string]interface{}{"Command": terminal.CommandColor("cf target -s")}))
    30  		return errors.New(message)
    31  	}
    32  
    33  	return nil
    34  }