blob: 978df7eabbf1979f0855d4aeda3f954cf36c8fd6 [file] [log] [blame]
David K. Bainbridge215e0242017-09-05 23:18:24 -07001package reference
2
3import "path"
4
5// IsNameOnly returns true if reference only contains a repo name.
6func IsNameOnly(ref Named) bool {
7 if _, ok := ref.(NamedTagged); ok {
8 return false
9 }
10 if _, ok := ref.(Canonical); ok {
11 return false
12 }
13 return true
14}
15
16// FamiliarName returns the familiar name string
17// for the given named, familiarizing if needed.
18func FamiliarName(ref Named) string {
19 if nn, ok := ref.(normalizedNamed); ok {
20 return nn.Familiar().Name()
21 }
22 return ref.Name()
23}
24
25// FamiliarString returns the familiar string representation
26// for the given reference, familiarizing if needed.
27func FamiliarString(ref Reference) string {
28 if nn, ok := ref.(normalizedNamed); ok {
29 return nn.Familiar().String()
30 }
31 return ref.String()
32}
33
34// FamiliarMatch reports whether ref matches the specified pattern.
35// See https://godoc.org/path#Match for supported patterns.
36func FamiliarMatch(pattern string, ref Reference) (bool, error) {
37 matched, err := path.Match(pattern, FamiliarString(ref))
38 if namedRef, isNamed := ref.(Named); isNamed && !matched {
39 matched, _ = path.Match(pattern, FamiliarName(namedRef))
40 }
41 return matched, err
42}