diff --git a/cmd/bin.go b/cmd/bin.go index 9daddf3b6..04994ae48 100644 --- a/cmd/bin.go +++ b/cmd/bin.go @@ -43,6 +43,7 @@ contains main package`, Action: runBin, Flags: []cli.Flag{ cli.BoolFlag{"dir, d", "build binary to given directory(second argument)"}, + cli.BoolFlag{"force, f", "force to update pakcage(s) and dependencies"}, }, } @@ -133,7 +134,7 @@ func runBin(ctx *cli.Context) { } defer func() { // Clean files. - os.RemoveAll(path.Join(repoPath, VENDOR)) + os.RemoveAll(path.Join(repoPath, doc.VENDOR)) }() // Check if previous steps were successful. @@ -156,7 +157,7 @@ func runBin(ctx *cli.Context) { if runtime.GOOS == "windows" { binName += ".exe" } - binPath := path.Join(VENDOR, "src", pkgPath, binName) + binPath := path.Join(doc.VENDOR, "src", pkgPath, binName) if !com.IsFile(binPath) { log.Error("Bin", "Fail to continue command") log.Fatal("", "Previous steps weren't successful or the project does not contain main package") diff --git a/cmd/build.go b/cmd/build.go index 0a5a4fe96..9de4d13a6 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -20,6 +20,7 @@ import ( "github.com/codegangsta/cli" + "github.com/gpmgo/gopm/doc" "github.com/gpmgo/gopm/log" ) @@ -49,7 +50,7 @@ func runBuild(ctx *cli.Context) { if isWindowsXP { binName := pkgName + ".exe" os.Remove(binName) - err = os.Rename(path.Join(VENDOR, "src", pkgName, binName), binName) + err = os.Rename(path.Join(doc.VENDOR, "src", pkgName, binName), binName) if err != nil { log.Error("Build", "Fail to move binary") log.Fatal("", err.Error()) diff --git a/cmd/gopath.go b/cmd/gopath.go index 4fadd9020..4a903ab08 100644 --- a/cmd/gopath.go +++ b/cmd/gopath.go @@ -15,8 +15,6 @@ import ( "github.com/gpmgo/gopm/log" ) -const VENDOR = ".vendor" - var isWindowsXP = false func getGopmPkgs(dirPath string, isTest bool) (pkgs map[string]*doc.Pkg, err error) { @@ -214,7 +212,7 @@ func genNewGoPath(ctx *cli.Context, isTest bool) { log.Fatal("", err.Error()) } - newGoPath = filepath.Join(curPath, VENDOR) + newGoPath = filepath.Join(curPath, doc.VENDOR) newGoPathSrc := filepath.Join(newGoPath, "src") os.RemoveAll(newGoPathSrc) os.MkdirAll(newGoPathSrc, os.ModePerm) diff --git a/cmd/install.go b/cmd/install.go index 5973ba60f..5bebc736a 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -15,6 +15,8 @@ package cmd import ( + "path/filepath" + "github.com/Unknwon/com" "github.com/codegangsta/cli" @@ -35,6 +37,7 @@ If no argument is supplied, then gopmfile must be present`, Action: runInstall, Flags: []cli.Flag{ cli.BoolFlag{"verbose, v", "show process details"}, + cli.BoolFlag{"pkg, p", "only install non-main packages"}, }, } @@ -57,22 +60,33 @@ func runInstall(ctx *cli.Context) { genNewGoPath(ctx, false) - if len(target) == 0 { - target = pkgName + var installRepos []string + if ctx.Bool("pkg") { + curPath, _ := filepath.Abs(".") + installRepos = doc.GetAllImports([]string{curPath}, + ".", ctx.Bool("example")) + } else { + if len(target) == 0 { + target = pkgName + } + + installRepos = []string{target} } log.Trace("Installing...") - cmdArgs := []string{"go", "install"} + for _, repo := range installRepos { + cmdArgs := []string{"go", "install"} - if ctx.Bool("verbose") { - cmdArgs = append(cmdArgs, "-v") - } - cmdArgs = append(cmdArgs, target) - err := execCmd(newGoPath, newCurPath, cmdArgs...) - if err != nil { - log.Error("Install", "Fail to install program") - log.Fatal("", err.Error()) + if ctx.Bool("verbose") { + cmdArgs = append(cmdArgs, "-v") + } + cmdArgs = append(cmdArgs, repo) + err := execCmd(newGoPath, newCurPath, cmdArgs...) + if err != nil { + log.Error("Install", "Fail to install program") + log.Fatal("", err.Error()) + } } log.Success("SUCC", "Install", "Command execute successfully!") diff --git a/doc/utils.go b/doc/utils.go index b0daae599..7cc054e83 100644 --- a/doc/utils.go +++ b/doc/utils.go @@ -26,6 +26,8 @@ import ( "github.com/gpmgo/gopm/log" ) +const VENDOR = ".vendor" + // GetDirsInfo returns os.FileInfo of all sub-directories in root path. func GetDirsInfo(rootPath string) []os.FileInfo { rootDir, err := os.Open(rootPath) @@ -59,7 +61,7 @@ func GetImports(absPath, importPath string, example bool) []string { dirs := make([]string, 0) for _, fi := range fis { - if fi.IsDir() { + if fi.IsDir() && !strings.Contains(fi.Name(), VENDOR) { dirs = append(dirs, absPath+fi.Name()) } }