Merge pull request #2143 from dmcgowan/reference-familiar-match

reference: move match function to helpers
This commit is contained in:
Stephen Day 2017-01-13 18:32:33 -08:00 committed by GitHub
commit 44eff0143e
4 changed files with 90 additions and 89 deletions

View file

@ -1,5 +1,7 @@
package reference
import "path"
// IsNameOnly returns true if reference only contains a repo name.
func IsNameOnly(ref Named) bool {
if _, ok := ref.(NamedTagged); ok {
@ -28,3 +30,13 @@ func FamiliarString(ref Reference) string {
}
return ref.String()
}
// FamiliarMatch reports whether ref matches the specified pattern.
// See https://godoc.org/path#Match for supported patterns.
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
}