github.com/cloudfoundry/cli@v7.1.0+incompatible/actor/actionerror/duplicate_service_error.go (about)

     1  package actionerror
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  )
     7  
     8  type DuplicateServiceError struct {
     9  	Name           string
    10  	ServiceBrokers []string
    11  }
    12  
    13  func (e DuplicateServiceError) Error() string {
    14  	message := " Specify a broker by using the '-b' flag."
    15  
    16  	if len(e.ServiceBrokers) != 0 {
    17  		message = fmt.Sprintf("\nSpecify a broker from available brokers %s by using the '-b' flag.", e.availableBrokers())
    18  	}
    19  
    20  	return fmt.Sprintf(
    21  		"Service '%s' is provided by multiple service brokers.%s", e.Name, message)
    22  }
    23  
    24  func (e DuplicateServiceError) availableBrokers() string {
    25  	var quotedBrokers []string
    26  	for _, broker := range e.ServiceBrokers {
    27  		quotedBrokers = append(quotedBrokers, fmt.Sprintf("'%s'", broker))
    28  	}
    29  	availableBrokers := strings.Join(quotedBrokers, ", ")
    30  	return availableBrokers
    31  }