Browse Source

Added install -pkg to only install non-main packages

pull/103/head
Unknown 11 years ago
parent
commit
c8bb27e8c4
  1. 5
      cmd/bin.go
  2. 3
      cmd/build.go
  3. 4
      cmd/gopath.go
  4. 16
      cmd/install.go
  5. 4
      doc/utils.go

5
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")

3
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())

4
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)

16
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,23 +60,34 @@ func runInstall(ctx *cli.Context) {
genNewGoPath(ctx, false)
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...")
for _, repo := range installRepos {
cmdArgs := []string{"go", "install"}
if ctx.Bool("verbose") {
cmdArgs = append(cmdArgs, "-v")
}
cmdArgs = append(cmdArgs, target)
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!")
}

4
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())
}
}

Loading…
Cancel
Save