2016-11-11 20:07:27 +00:00
|
|
|
package reference
|
|
|
|
|
2017-01-14 01:08:46 +00:00
|
|
|
import "path"
|
|
|
|
|
2016-11-11 20:07:27 +00:00
|
|
|
// IsNameOnly returns true if reference only contains a repo name.
|
|
|
|
func IsNameOnly(ref Named) bool {
|
|
|
|
if _, ok := ref.(NamedTagged); ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if _, ok := ref.(Canonical); ok {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
2016-06-27 23:41:28 +00:00
|
|
|
|
|
|
|
// FamiliarName returns the familiar name string
|
|
|
|
// for the given named, familiarizing if needed.
|
|
|
|
func FamiliarName(ref Named) string {
|
2017-01-11 20:58:00 +00:00
|
|
|
if nn, ok := ref.(normalizedNamed); ok {
|
2016-06-27 23:41:28 +00:00
|
|
|
return nn.Familiar().Name()
|
|
|
|
}
|
|
|
|
return ref.Name()
|
|
|
|
}
|
|
|
|
|
|
|
|
// FamiliarString returns the familiar string representation
|
|
|
|
// for the given reference, familiarizing if needed.
|
|
|
|
func FamiliarString(ref Reference) string {
|
2017-01-11 20:58:00 +00:00
|
|
|
if nn, ok := ref.(normalizedNamed); ok {
|
2016-06-27 23:41:28 +00:00
|
|
|
return nn.Familiar().String()
|
|
|
|
}
|
|
|
|
return ref.String()
|
|
|
|
}
|
2017-01-14 01:08:46 +00:00
|
|
|
|
|
|
|
// FamiliarMatch reports whether ref matches the specified pattern.
|
2022-11-11 14:02:10 +00:00
|
|
|
// See [path.Match] for supported patterns.
|
2017-01-14 01:08:46 +00:00
|
|
|
func FamiliarMatch(pattern string, ref Reference) (bool, error) {
|
|
|
|
matched, err := path.Match(pattern, FamiliarString(ref))
|
|
|
|
if namedRef, isNamed := ref.(Named); isNamed && !matched {
|
|
|
|
matched, _ = path.Match(pattern, FamiliarName(namedRef))
|
|
|
|
}
|
|
|
|
return matched, err
|
|
|
|
}
|