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