github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/requirements/api_endpoint.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 APIEndpointRequirement struct {
    15  	config coreconfig.Reader
    16  }
    17  
    18  func NewAPIEndpointRequirement(config coreconfig.Reader) APIEndpointRequirement {
    19  	return APIEndpointRequirement{config}
    20  }
    21  
    22  func (req APIEndpointRequirement) Execute() error {
    23  	if req.config.APIEndpoint() == "" {
    24  		loginTip := terminal.CommandColor(fmt.Sprintf("%s login", cf.Name))
    25  		apiTip := terminal.CommandColor(fmt.Sprintf("%s api", cf.Name))
    26  		return errors.New(T("No API endpoint set. Use '{{.LoginTip}}' or '{{.APITip}}' to target an endpoint.",
    27  			map[string]interface{}{
    28  				"LoginTip": loginTip,
    29  				"APITip":   apiTip,
    30  			}))
    31  	}
    32  
    33  	return nil
    34  }