From 8a9af33071979245f87729a3edef0e242843bd11 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Fri, 27 May 2016 13:11:10 -0700 Subject: [PATCH] Update manifest.Fetch to also parse "tag" from repo strings --- manifest/fetch.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/manifest/fetch.go b/manifest/fetch.go index 8eae335..c543315 100644 --- a/manifest/fetch.go +++ b/manifest/fetch.go @@ -2,11 +2,12 @@ package manifest import ( "fmt" - "os" "net/http" "net/url" + "os" "path" "path/filepath" + "strings" ) // "dir" is the default "library directory" @@ -14,19 +15,26 @@ import ( // if "repo" is a URL, the remote contents of that URL // the file "repo" // the file "dir/repo" -func Fetch(dir, repo string) (string, *Manifest2822, error) { +// (repoName, tagName, man, err) +func Fetch(dir, repo string) (string, string, *Manifest2822, error) { repoName := path.Base(repo) + tagName := "" + if tagIndex := strings.IndexRune(repoName, ':'); tagIndex > 0 { + tagName = repoName[tagIndex+1:] + repoName = repoName[:tagIndex] + repo = strings.TrimSuffix(repo, ":"+tagName) + } u, err := url.Parse(repo) if err == nil && u.IsAbs() { // must be remote URL! resp, err := http.Get(repo) if err != nil { - return repoName, nil, err + return repoName, tagName, nil, err } defer resp.Body.Close() man, err := Parse(resp.Body) - return repoName, man, err + return repoName, tagName, man, err } // try file paths @@ -36,14 +44,14 @@ func Fetch(dir, repo string) (string, *Manifest2822, error) { } { f, err := os.Open(fileName) if err != nil && !os.IsNotExist(err) { - return repoName, nil, err + return repoName, tagName, nil, err } if err == nil { defer f.Close() man, err := Parse(f) - return repoName, man, err + return repoName, tagName, man, err } } - return repoName, nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, dir) + return repoName, tagName, nil, fmt.Errorf("unable to find a manifest named %q (in %q or as a remote URL)", repo, dir) }