github.com/lukasheimann/cloudfoundrycli@v7.1.0+incompatible/command/translatableerror/plugin_commands_conflict_error.go (about)

     1  package translatableerror
     2  
     3  import "strings"
     4  
     5  // PluginCommandsConflictError is returned when a plugin command name conflicts
     6  // with a native or existing plugin command name.
     7  type PluginCommandsConflictError struct {
     8  	PluginName     string
     9  	PluginVersion  string
    10  	CommandNames   []string
    11  	CommandAliases []string
    12  }
    13  
    14  func (e PluginCommandsConflictError) Error() string {
    15  	switch {
    16  	case len(e.CommandNames) > 0 && len(e.CommandAliases) > 0:
    17  		return "Plugin {{.PluginName}} v{{.PluginVersion}} could not be installed as it contains commands with names and aliases that are already used: {{.CommandNamesAndAliases}}."
    18  	case len(e.CommandNames) > 0:
    19  		return "Plugin {{.PluginName}} v{{.PluginVersion}} could not be installed as it contains commands with names that are already used: {{.CommandNames}}."
    20  	case len(e.CommandAliases) > 0:
    21  		return "Plugin {{.PluginName}} v{{.PluginVersion}} could not be installed as it contains commands with aliases that are already used: {{.CommandAliases}}."
    22  	default:
    23  		return "Plugin {{.PluginName}} v{{.PluginVersion}} could not be installed as it contains commands with names or aliases that are already used."
    24  	}
    25  }
    26  
    27  func (e PluginCommandsConflictError) Translate(translate func(string, ...interface{}) string) string {
    28  	return translate(e.Error(), map[string]interface{}{
    29  		"PluginName":             e.PluginName,
    30  		"PluginVersion":          e.PluginVersion,
    31  		"CommandNames":           strings.Join(e.CommandNames, ", "),
    32  		"CommandAliases":         strings.Join(e.CommandAliases, ", "),
    33  		"CommandNamesAndAliases": strings.Join(append(e.CommandNames, e.CommandAliases...), ", "),
    34  	})
    35  }