github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/requirements/targeted_space.go (about)

     1  package requirements
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/cloudfoundry/cli/cf"
     6  	"github.com/cloudfoundry/cli/cf/configuration/core_config"
     7  	. "github.com/cloudfoundry/cli/cf/i18n"
     8  	"github.com/cloudfoundry/cli/cf/terminal"
     9  )
    10  
    11  type TargetedSpaceRequirement struct {
    12  	ui     terminal.UI
    13  	config core_config.Reader
    14  }
    15  
    16  func NewTargetedSpaceRequirement(ui terminal.UI, config core_config.Reader) TargetedSpaceRequirement {
    17  	return TargetedSpaceRequirement{ui, config}
    18  }
    19  
    20  func (req TargetedSpaceRequirement) Execute() (success bool) {
    21  	if !req.config.HasOrganization() {
    22  		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")}))
    23  		req.ui.Failed(message)
    24  		return false
    25  	}
    26  
    27  	if !req.config.HasSpace() {
    28  		message := fmt.Sprintf(T("No space targeted, use '{{.Command}}' to target a space", map[string]interface{}{"Command": terminal.CommandColor("cf target -s")}))
    29  		req.ui.Failed(message)
    30  		return false
    31  	}
    32  
    33  	return true
    34  }