github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/cf/requirements/api_endpoint.go (about)

     1  package requirements
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"errors"
     7  	"github.com/cloudfoundry/cli/cf"
     8  	"github.com/cloudfoundry/cli/cf/configuration/coreconfig"
     9  	. "github.com/cloudfoundry/cli/cf/i18n"
    10  	"github.com/cloudfoundry/cli/cf/terminal"
    11  )
    12  
    13  type APIEndpointRequirement struct {
    14  	config coreconfig.Reader
    15  }
    16  
    17  func NewAPIEndpointRequirement(config coreconfig.Reader) APIEndpointRequirement {
    18  	return APIEndpointRequirement{config}
    19  }
    20  
    21  func (req APIEndpointRequirement) Execute() error {
    22  	if req.config.APIEndpoint() == "" {
    23  		loginTip := terminal.CommandColor(fmt.Sprintf(T("{{.CFName}} login", map[string]interface{}{"CFName": cf.Name})))
    24  		apiTip := terminal.CommandColor(fmt.Sprintf(T("{{.CFName}} api", map[string]interface{}{"CFName": cf.Name})))
    25  		return errors.New(T("No API endpoint set. Use '{{.LoginTip}}' or '{{.APITip}}' to target an endpoint.",
    26  			map[string]interface{}{
    27  				"LoginTip": loginTip,
    28  				"APITip":   apiTip,
    29  			}))
    30  	}
    31  
    32  	return nil
    33  }