Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix `go get`.

  • Loading branch information...
commit 6af810383af06b611f97252d8d2355f0582e8205 1 parent 1f7910f
@AlekSi authored
Showing with 55 additions and 35 deletions.
  1. +2 −2 integration_test/remote_test.go
  2. +28 −16 nut/get.go
  3. +25 −17 nut/get_test.go
View
4 integration_test/remote_test.go
@@ -61,6 +61,6 @@ func (*R) TestPublishGet(c *C) {
c.Check(strings.HasSuffix(stderr, `Nut debug/test_nut2 version 0.0.2 published.`), Equals, true)
gitNoDiff(c, TestNut2)
- // _, stderr = runNut(c, "", "get -v test_nut2/0.0.2")
- // c.Check(strings.HasSuffix(stderr, `Nut "test_nut2" version "0.0.2" published.`), Equals, true)
+ _, stderr = runNut(c, "", "get -v debug/test_nut2/0.0.2")
+ c.Check(strings.HasSuffix(stderr, `gonuts.io/debug/test_nut2`), Equals, true)
}
View
44 nut/get.go
@@ -11,6 +11,7 @@ import (
"net/http"
"net/url"
"path/filepath"
+ "sort"
"strings"
. "github.com/AlekSi/nut"
@@ -44,7 +45,8 @@ Examples:
cmdGet.Flag.BoolVar(&getV, "v", false, vHelp)
}
-func ArgToURL(s string) *url.URL {
+// Parse argument, return URL to get nut from and install prefix.
+func ParseArg(s string) (u *url.URL, prefix string) {
var p []string
var host string
var ok bool
@@ -56,7 +58,8 @@ func ArgToURL(s string) *url.URL {
p = strings.Split(s, "/")
if len(p) > 0 {
- host, ok = NutImportPrefixes[p[0]]
+ prefix = p[0]
+ host, ok = NutImportPrefixes[prefix]
}
if ok {
// import path style
@@ -64,13 +67,26 @@ func ArgToURL(s string) *url.URL {
s = strings.Join(p, "/")
} else {
// short style
- s = fmt.Sprintf("http://%s/%s", NutImportPrefixes["gonuts.io"], s)
+ prefix = "gonuts.io"
+ host = NutImportPrefixes[prefix]
+ s = fmt.Sprintf("http://%s/%s", host, s)
}
parse:
u, err := url.Parse(s)
FatalIfErr(err)
- return u
+ if prefix == "" {
+ prefix = u.Host
+ if strings.Contains(prefix, ":") {
+ prefix, _, err = net.SplitHostPort(prefix)
+ FatalIfErr(err)
+ }
+ if strings.HasPrefix(prefix, "www.") {
+ prefix = prefix[4:]
+ }
+ }
+
+ return
}
func get(url *url.URL) (b []byte, err error) {
@@ -130,7 +146,7 @@ func runGet(cmd *Command) {
arg := args[0]
args = args[1:]
- url := ArgToURL(arg)
+ url, prefix := ParseArg(arg)
b, err := get(url)
if err != nil {
log.Print(err)
@@ -159,24 +175,20 @@ func runGet(cmd *Command) {
p := getP
if p == "" {
- if strings.Contains(url.Host, ":") {
- p, _, err = net.SplitHostPort(url.Host)
- FatalIfErr(err)
- } else {
- p = url.Host
- }
- if strings.HasPrefix(p, "www.") {
- p = p[4:]
- }
+ p = prefix
}
fileName := WriteNut(b, p, getV)
- path := filepath.Join(p, nf.Name, nf.Version.String())
-
+ path := nf.ImportPath(p)
UnpackNut(fileName, filepath.Join(SrcDir, path), true, getV)
installPaths[path] = true
}
+ paths := make([]string, 0, len(installPaths))
for path := range installPaths {
+ paths = append(paths, path)
+ }
+ sort.Strings(paths)
+ for _, path := range paths {
InstallPackage(path, getV)
}
}
View
42 nut/get_test.go
@@ -22,23 +22,31 @@ func (g *G) TearDownSuite(*C) {
delete(NutImportPrefixes, "express42.com")
}
-func (*G) TestArgToURL(c *C) {
- // short style
- c.Check(ArgToURL("AlekSi/test_nut1").String(), Equals, "http://server/AlekSi/test_nut1")
- c.Check(ArgToURL("AlekSi/test_nut1/0.0.1").String(), Equals, "http://server/AlekSi/test_nut1/0.0.1")
-
- // import path style
- c.Check(ArgToURL("gonuts.io/AlekSi/test_nut1").String(), Equals, "http://server/AlekSi/test_nut1")
- c.Check(ArgToURL("gonuts.io/AlekSi/test_nut1/0.0.1").String(), Equals, "http://server/AlekSi/test_nut1/0.0.1")
- c.Check(ArgToURL("express42.com/nuts/AlekSi/test_nut1").String(), Equals, "http://express42.com/nuts/AlekSi/test_nut1")
- c.Check(ArgToURL("express42.com/nuts/AlekSi/test_nut1/0.0.1").String(), Equals, "http://express42.com/nuts/AlekSi/test_nut1/0.0.1")
-
- // full URL - as is
- c.Check(ArgToURL("http://www.gonuts.io/AlekSi/test_nut1").String(), Equals, "http://www.gonuts.io/AlekSi/test_nut1")
- c.Check(ArgToURL("http://www.gonuts.io/AlekSi/test_nut1/0.0.1").String(), Equals, "http://www.gonuts.io/AlekSi/test_nut1/0.0.1")
- c.Check(ArgToURL("http://localhost:8080/AlekSi/test_nut1-0.0.1.nut").String(), Equals, "http://localhost:8080/AlekSi/test_nut1-0.0.1.nut")
- c.Check(ArgToURL("http://example.com/nuts/test_nut1-0.0.1.nut").String(), Equals, "http://example.com/nuts/test_nut1-0.0.1.nut")
- c.Check(ArgToURL("https://example.com/nuts/test_nut1-0.0.1.nut").String(), Equals, "https://example.com/nuts/test_nut1-0.0.1.nut")
+func (*G) TestParseArg(c *C) {
+ data := [][3]string{
+ // short style
+ {"AlekSi/test_nut1", "http://server/AlekSi/test_nut1", "gonuts.io"},
+ {"AlekSi/test_nut1/0.0.1", "http://server/AlekSi/test_nut1/0.0.1", "gonuts.io"},
+
+ // import path style
+ {"gonuts.io/AlekSi/test_nut1", "http://server/AlekSi/test_nut1", "gonuts.io"},
+ {"gonuts.io/AlekSi/test_nut1/0.0.1", "http://server/AlekSi/test_nut1/0.0.1", "gonuts.io"},
+ {"express42.com/nuts/AlekSi/test_nut1", "http://express42.com/nuts/AlekSi/test_nut1", "express42.com"},
+ {"express42.com/nuts/AlekSi/test_nut1/0.0.1", "http://express42.com/nuts/AlekSi/test_nut1/0.0.1", "express42.com"},
+
+ // full URL - as is
+ {"http://www.gonuts.io/AlekSi/test_nut1", "http://www.gonuts.io/AlekSi/test_nut1", "gonuts.io"},
+ {"http://www.gonuts.io/AlekSi/test_nut1/0.0.1", "http://www.gonuts.io/AlekSi/test_nut1/0.0.1", "gonuts.io"},
+ {"http://localhost:8080/AlekSi/test_nut1-0.0.1.nut", "http://localhost:8080/AlekSi/test_nut1-0.0.1.nut", "localhost"},
+ {"http://example.com/nuts/test_nut1-0.0.1.nut", "http://example.com/nuts/test_nut1-0.0.1.nut", "example.com"},
+ {"https://example.com/nuts/test_nut1-0.0.1.nut", "https://example.com/nuts/test_nut1-0.0.1.nut", "example.com"},
+ }
+
+ for _, d := range data {
+ u, prefix := ParseArg(d[0])
+ c.Check(u.String(), Equals, d[1])
+ c.Check(prefix, Equals, d[2])
+ }
}
func (*G) TestNutImports(c *C) {
Please sign in to comment.
Something went wrong with that request. Please try again.