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. 36
      cmd/install.go
  5. 4
      doc/utils.go

5
cmd/bin.go

@ -43,6 +43,7 @@ contains main package`,
Action: runBin, Action: runBin,
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.BoolFlag{"dir, d", "build binary to given directory(second argument)"}, 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() { defer func() {
// Clean files. // Clean files.
os.RemoveAll(path.Join(repoPath, VENDOR)) os.RemoveAll(path.Join(repoPath, doc.VENDOR))
}() }()
// Check if previous steps were successful. // Check if previous steps were successful.
@ -156,7 +157,7 @@ func runBin(ctx *cli.Context) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
binName += ".exe" binName += ".exe"
} }
binPath := path.Join(VENDOR, "src", pkgPath, binName) binPath := path.Join(doc.VENDOR, "src", pkgPath, binName)
if !com.IsFile(binPath) { if !com.IsFile(binPath) {
log.Error("Bin", "Fail to continue command") log.Error("Bin", "Fail to continue command")
log.Fatal("", "Previous steps weren't successful or the project does not contain main package") 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/codegangsta/cli"
"github.com/gpmgo/gopm/doc"
"github.com/gpmgo/gopm/log" "github.com/gpmgo/gopm/log"
) )
@ -49,7 +50,7 @@ func runBuild(ctx *cli.Context) {
if isWindowsXP { if isWindowsXP {
binName := pkgName + ".exe" binName := pkgName + ".exe"
os.Remove(binName) 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 { if err != nil {
log.Error("Build", "Fail to move binary") log.Error("Build", "Fail to move binary")
log.Fatal("", err.Error()) log.Fatal("", err.Error())

4
cmd/gopath.go

@ -15,8 +15,6 @@ import (
"github.com/gpmgo/gopm/log" "github.com/gpmgo/gopm/log"
) )
const VENDOR = ".vendor"
var isWindowsXP = false var isWindowsXP = false
func getGopmPkgs(dirPath string, isTest bool) (pkgs map[string]*doc.Pkg, err error) { 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()) log.Fatal("", err.Error())
} }
newGoPath = filepath.Join(curPath, VENDOR) newGoPath = filepath.Join(curPath, doc.VENDOR)
newGoPathSrc := filepath.Join(newGoPath, "src") newGoPathSrc := filepath.Join(newGoPath, "src")
os.RemoveAll(newGoPathSrc) os.RemoveAll(newGoPathSrc)
os.MkdirAll(newGoPathSrc, os.ModePerm) os.MkdirAll(newGoPathSrc, os.ModePerm)

36
cmd/install.go

@ -15,6 +15,8 @@
package cmd package cmd
import ( import (
"path/filepath"
"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/codegangsta/cli" "github.com/codegangsta/cli"
@ -35,6 +37,7 @@ If no argument is supplied, then gopmfile must be present`,
Action: runInstall, Action: runInstall,
Flags: []cli.Flag{ Flags: []cli.Flag{
cli.BoolFlag{"verbose, v", "show process details"}, 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) genNewGoPath(ctx, false)
if len(target) == 0 { var installRepos []string
target = pkgName 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...") log.Trace("Installing...")
cmdArgs := []string{"go", "install"} for _, repo := range installRepos {
cmdArgs := []string{"go", "install"}
if ctx.Bool("verbose") { if ctx.Bool("verbose") {
cmdArgs = append(cmdArgs, "-v") cmdArgs = append(cmdArgs, "-v")
} }
cmdArgs = append(cmdArgs, target) cmdArgs = append(cmdArgs, repo)
err := execCmd(newGoPath, newCurPath, cmdArgs...) err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil { if err != nil {
log.Error("Install", "Fail to install program") log.Error("Install", "Fail to install program")
log.Fatal("", err.Error()) log.Fatal("", err.Error())
}
} }
log.Success("SUCC", "Install", "Command execute successfully!") log.Success("SUCC", "Install", "Command execute successfully!")

4
doc/utils.go

@ -26,6 +26,8 @@ import (
"github.com/gpmgo/gopm/log" "github.com/gpmgo/gopm/log"
) )
const VENDOR = ".vendor"
// GetDirsInfo returns os.FileInfo of all sub-directories in root path. // GetDirsInfo returns os.FileInfo of all sub-directories in root path.
func GetDirsInfo(rootPath string) []os.FileInfo { func GetDirsInfo(rootPath string) []os.FileInfo {
rootDir, err := os.Open(rootPath) rootDir, err := os.Open(rootPath)
@ -59,7 +61,7 @@ func GetImports(absPath, importPath string, example bool) []string {
dirs := make([]string, 0) dirs := make([]string, 0)
for _, fi := range fis { for _, fi := range fis {
if fi.IsDir() { if fi.IsDir() && !strings.Contains(fi.Name(), VENDOR) {
dirs = append(dirs, absPath+fi.Name()) dirs = append(dirs, absPath+fi.Name())
} }
} }

Loading…
Cancel
Save