|
|
|
@ -21,7 +21,10 @@ import (
|
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
|
"github.com/codegangsta/cli" |
|
|
|
|
|
|
|
|
|
"github.com/gpmgo/gopm/doc" |
|
|
|
|
"github.com/gpmgo/gopm/log" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
@ -31,39 +34,83 @@ var (
|
|
|
|
|
failConut int |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var CmdGet = &Command{ |
|
|
|
|
UsageLine: "get [flags] <package(s)>", |
|
|
|
|
Short: "download and install packages and dependencies", |
|
|
|
|
Long: ` |
|
|
|
|
Get downloads and installs the packages named by the import paths, |
|
|
|
|
along with their dependencies. |
|
|
|
|
|
|
|
|
|
This command works even you haven't installed any version control tool |
|
|
|
|
such as git, hg, etc. |
|
|
|
|
|
|
|
|
|
The install flags are: |
|
|
|
|
var CmdGet = cli.Command{ |
|
|
|
|
Name: "get", |
|
|
|
|
Usage: "fetch remote package(s) and dependencies to local repository", |
|
|
|
|
Description: `Command get fetches a package, and any pakcages that it depents on.
|
|
|
|
|
If the package has a gopmfile, the fetch process will be driven by that. |
|
|
|
|
|
|
|
|
|
-d |
|
|
|
|
download without installing package(s). |
|
|
|
|
-u |
|
|
|
|
force to update pakcage(s). |
|
|
|
|
-e |
|
|
|
|
download dependencies for example(s). |
|
|
|
|
gopm get |
|
|
|
|
gopm get <import path>@[<tag|commit|branch>:<value>] |
|
|
|
|
gopm get <package name>@[<tag|commit|branch>:<value>] |
|
|
|
|
|
|
|
|
|
The list flags accept a space-separated list of strings. |
|
|
|
|
Can specify one or more: gopm get beego@tag:v0.9.0 github.com/beego/bee |
|
|
|
|
|
|
|
|
|
For more about specifying packages, see 'go help packages'. |
|
|
|
|
`, |
|
|
|
|
If no argument is supplied, then gopmfile must be present`, |
|
|
|
|
Action: runGet, |
|
|
|
|
Flags: []cli.Flag{ |
|
|
|
|
cli.BoolFlag{"force", "force to update pakcage(s) and dependencies"}, |
|
|
|
|
cli.BoolFlag{"example", "download dependencies for example(s)"}, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func init() { |
|
|
|
|
downloadCache = make(map[string]bool) |
|
|
|
|
CmdGet.Run = runGet |
|
|
|
|
CmdGet.Flags = map[string]bool{ |
|
|
|
|
"-d": false, |
|
|
|
|
"-u": false, |
|
|
|
|
"-e": false, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func runGet(ctx *cli.Context) { |
|
|
|
|
// Check number of arguments.
|
|
|
|
|
switch len(ctx.Args()) { |
|
|
|
|
case 0: |
|
|
|
|
getByGopmfile(ctx) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func getByGopmfile(ctx *cli.Context) { |
|
|
|
|
if !com.IsFile(".gopmfile") { |
|
|
|
|
log.Fatal("install", "No argument is supplied and no gopmfile exist") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hd, err := com.HomeDir() |
|
|
|
|
if err != nil { |
|
|
|
|
log.Error("install", "Fail to get current user") |
|
|
|
|
log.Fatal("", err.Error()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
installRepoPath = strings.Replace(reposDir, "~", hd, -1) |
|
|
|
|
log.Log("Local repository path: %s", installRepoPath) |
|
|
|
|
|
|
|
|
|
// TODO: 获取依赖包
|
|
|
|
|
|
|
|
|
|
log.Error("install", "command haven't done yet!") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func processGet() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func runGet1(cmd *Command, args []string) { |
|
|
|
|
nodes := []*doc.Node{} |
|
|
|
|
// ver describles branch, tag or commit.
|
|
|
|
|
var t, ver string = doc.BRANCH, "" |
|
|
|
|
|
|
|
|
|
var err error |
|
|
|
|
if len(args) >= 2 { |
|
|
|
|
t, ver, err = validPath(args[1]) |
|
|
|
|
if err != nil { |
|
|
|
|
com.ColorLog("[ERROR] Fail to parse 'args'[ %s ]\n", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
node := doc.NewNode(args[0], args[0], t, ver, true) |
|
|
|
|
nodes = append(nodes, node) |
|
|
|
|
|
|
|
|
|
// Download package(s).
|
|
|
|
|
downloadPackages(nodes) |
|
|
|
|
|
|
|
|
|
com.ColorLog("[INFO] %d package(s) downloaded, %d failed.\n", |
|
|
|
|
downloadCount, failConut) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// printGetPrompt prints prompt information to users to
|
|
|
|
@ -107,51 +154,6 @@ func checkFlags(flags map[string]bool, args []string, print func(string)) int {
|
|
|
|
|
return num |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func runGet(cmd *Command, args []string) { |
|
|
|
|
// Check flags.
|
|
|
|
|
num := checkFlags(cmd.Flags, args, printGetPrompt) |
|
|
|
|
if num == -1 { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
args = args[num:] |
|
|
|
|
|
|
|
|
|
// Check length of arguments.
|
|
|
|
|
if len(args) < 1 { |
|
|
|
|
com.ColorLog("[ERRO] Please list the package that you want to install.\n") |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
hd, err := com.HomeDir() |
|
|
|
|
if err != nil { |
|
|
|
|
com.ColorLog("[ERRO] Fail to get current user[ %s ]\n", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
installRepoPath = strings.Replace(reposDir, "~", hd, -1) |
|
|
|
|
com.ColorLog("[INFO] Packages will be installed into( %s )\n", installRepoPath) |
|
|
|
|
|
|
|
|
|
nodes := []*doc.Node{} |
|
|
|
|
// ver describles branch, tag or commit.
|
|
|
|
|
var t, ver string = doc.BRANCH, "" |
|
|
|
|
|
|
|
|
|
if len(args) >= 2 { |
|
|
|
|
t, ver, err = validPath(args[1]) |
|
|
|
|
if err != nil { |
|
|
|
|
com.ColorLog("[ERROR] Fail to parse 'args'[ %s ]\n", err) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
node := doc.NewNode(args[0], args[0], t, ver, true) |
|
|
|
|
nodes = append(nodes, node) |
|
|
|
|
|
|
|
|
|
// Download package(s).
|
|
|
|
|
downloadPackages(nodes) |
|
|
|
|
|
|
|
|
|
com.ColorLog("[INFO] %d package(s) downloaded, %d failed.\n", |
|
|
|
|
downloadCount, failConut) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// downloadPackages downloads packages with certain commit,
|
|
|
|
|
// if the commit is empty string, then it downloads all dependencies,
|
|
|
|
|
// otherwise, it only downloada package with specific commit only.
|
|
|
|
@ -160,18 +162,18 @@ func downloadPackages(nodes []*doc.Node) {
|
|
|
|
|
for _, n := range nodes { |
|
|
|
|
// Check if it is a valid remote path.
|
|
|
|
|
if doc.IsValidRemotePath(n.ImportPath) { |
|
|
|
|
if !CmdGet.Flags["-u"] { |
|
|
|
|
// Check if package has been downloaded.
|
|
|
|
|
installPath := installRepoPath + "/" + doc.GetProjectPath(n.ImportPath) |
|
|
|
|
if len(n.Value) > 0 { |
|
|
|
|
installPath += "." + n.Value |
|
|
|
|
} |
|
|
|
|
if com.IsExist(installPath) { |
|
|
|
|
com.ColorLog("[WARN] Skipped installed package( %s => %s:%s )\n", |
|
|
|
|
n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// if !CmdGet.Flags["-u"] {
|
|
|
|
|
// // Check if package has been downloaded.
|
|
|
|
|
// installPath := installRepoPath + "/" + doc.GetProjectPath(n.ImportPath)
|
|
|
|
|
// if len(n.Value) > 0 {
|
|
|
|
|
// installPath += "." + n.Value
|
|
|
|
|
// }
|
|
|
|
|
// if com.IsExist(installPath) {
|
|
|
|
|
// com.ColorLog("[WARN] Skipped installed package( %s => %s:%s )\n",
|
|
|
|
|
// n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))
|
|
|
|
|
// continue
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
if !downloadCache[n.ImportPath] { |
|
|
|
|
// Download package.
|
|
|
|
@ -216,7 +218,7 @@ func downloadPackage(nod *doc.Node) (*doc.Node, []string) {
|
|
|
|
|
// Mark as donwloaded.
|
|
|
|
|
downloadCache[nod.ImportPath] = true |
|
|
|
|
|
|
|
|
|
imports, err := doc.PureDownload(nod, installRepoPath, CmdGet.Flags) |
|
|
|
|
imports, err := doc.PureDownload(nod, installRepoPath, nil) //CmdGet.Flags)
|
|
|
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
com.ColorLog("[ERRO] Download falied( %s )[ %s ]\n", nod.ImportPath, err) |
|
|
|
|