forked from openshift/origin
/
errors.go
51 lines (40 loc) · 1.16 KB
/
errors.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package app
import (
"bytes"
"fmt"
)
type ErrNoMatch struct {
value string
qualifier string
}
func (e ErrNoMatch) Error() string {
if len(e.qualifier) != 0 {
return fmt.Sprintf("no image matched %q: %s", e.value, e.qualifier)
}
return fmt.Sprintf("no image matched %q", e.value)
}
func (e ErrNoMatch) UsageError(commandName string) string {
return fmt.Sprintf("%[3]s - does a Docker image with that name exist?", e.value, commandName, e.Error())
/*`
%[3]s - you can try to search for images or templates that may match this name with:
$ %[2]s -S %[1]q
`*/
}
type ErrMultipleMatches struct {
Image string
Matches []*ComponentMatch
}
func (e ErrMultipleMatches) Error() string {
return fmt.Sprintf("multiple images matched %q: %d", e.Image, len(e.Matches))
}
func (e ErrMultipleMatches) UsageError(commandName string) string {
buf := &bytes.Buffer{}
for _, match := range e.Matches {
fmt.Fprintf(buf, "* %[1]s (use %[2]s)\n", match.Name, match.Argument)
fmt.Fprintf(buf, " %s\n\n", match.Description)
}
return fmt.Sprintf(`
The argument %[1]q could apply to the following images or image repositories:
%[2]s
`, e.Image, buf.String())
}