diff --git a/cmd/build.go b/cmd/build.go index aa4690cbb..2e128477d 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -17,6 +17,7 @@ package cmd import ( "github.com/codegangsta/cli" + "github.com/gpmgo/gopm/doc" "github.com/gpmgo/gopm/log" ) @@ -31,6 +32,7 @@ gopm build `, } func runBuild(ctx *cli.Context) { + doc.LoadLocalNodes() genNewGoPath(ctx, false) log.Trace("Building...") diff --git a/cmd/get.go b/cmd/get.go index c11d2c713..39f37c6dc 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -51,6 +51,7 @@ Can specify one or more: gopm get beego@tag:v0.9.0 github.com/beego/bee If no argument is supplied, then gopmfile must be present`, Action: runGet, Flags: []cli.Flag{ + cli.BoolFlag{"gopath", "download package(s) to GOPATH"}, cli.BoolFlag{"force", "force to update pakcage(s) and dependencies"}, cli.BoolFlag{"example", "download dependencies for example(s)"}, }, @@ -70,8 +71,19 @@ func runGet(ctx *cli.Context) { doc.HomeDir = strings.Replace(doc.RawHomeDir, "~", hd, -1) doc.LoadPkgNameList(doc.HomeDir + "/data/pkgname.list") - installRepoPath = doc.HomeDir + "/repos" - log.Log("Local repository path: %s", installRepoPath) + if ctx.Bool("gopath") { + installRepoPath = com.GetGOPATHs()[0] + if !com.IsDir(installRepoPath) { + log.Error("Get", "Fail to start command") + log.Fatal("", "GOPATH does not exist: "+installRepoPath) + } + log.Log("Indicate GOPATH: %s", installRepoPath) + + installRepoPath += "/src" + } else { + installRepoPath = doc.HomeDir + "/repos" + log.Log("Local repository path: %s", installRepoPath) + } // Check number of arguments. switch len(ctx.Args()) { @@ -80,6 +92,7 @@ func runGet(ctx *cli.Context) { default: getByPath(ctx) } + } func getByGopmfile(ctx *cli.Context) { @@ -183,7 +196,7 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { // Check if it is a valid remote path. if doc.IsValidRemotePath(n.ImportPath) { installPath := installRepoPath + "/" + doc.GetProjectPath(n.ImportPath) - if len(n.Value) > 0 { + if len(n.Value) > 0 && !ctx.Bool("gopath") { installPath += "." + n.Value } @@ -279,6 +292,15 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) { os.RemoveAll(installRepoPath + "/" + doc.GetProjectPath(nod.ImportPath) + "/") return nil, nil } + + suf := "." + nod.Value + if len(suf) == 1 { + suf = "" + } + if ctx.Bool("gopath") && len(suf) > 0 { + os.RemoveAll(installRepoPath + "/" + nod.ImportPath) + os.Rename(installRepoPath+"/"+nod.ImportPath+suf, installRepoPath+"/"+nod.ImportPath) + } return nod, imports } diff --git a/doc/github.go b/doc/github.go index c7885cbd3..96d4d8322 100644 --- a/doc/github.go +++ b/doc/github.go @@ -70,7 +70,7 @@ func getGithubDoc(client *http.Client, match map[string]string, installRepoPath break COMMIT_LOOP } } - if etag == nod.Revision { + if etag == nod.Revision && !ctx.Bool("gopath") { log.Log("GET Package hasn't changed: %s", nod.ImportPath) return nil, nil } diff --git a/doc/google.go b/doc/google.go index 404c33a41..6e95bc20f 100644 --- a/doc/google.go +++ b/doc/google.go @@ -64,7 +64,7 @@ func getGoogleDoc(client *http.Client, match map[string]string, installRepoPath if m := googleRevisionRe.FindSubmatch(p); m == nil { log.Error("GET", "Fail to get revision") log.Error("", err.Error()) - } else { + } else if !ctx.Bool("gopath") { etag := string(m[1]) if etag == nod.Revision { log.Log("GET Package hasn't changed: %s", nod.ImportPath) diff --git a/gopm.go b/gopm.go index 0386df4f0..7a8e289ad 100644 --- a/gopm.go +++ b/gopm.go @@ -29,7 +29,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.5.6.1130" +const APP_VER = "0.5.7.1130" // //cmd.CmdSearch, // cmdClean,