Browse Source

add update command: need verified

pull/103/head
Lunny Xiao 11 years ago
parent
commit
e2266fa829
  1. 5
      cmd/bin.go
  2. 3
      cmd/build.go
  3. 6
      cmd/gen.go
  4. 4
      cmd/gopath.go
  5. 16
      cmd/install.go
  6. 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())

6
cmd/gen.go

@ -58,8 +58,12 @@ func runGen(ctx *cli.Context) {
} }
// Get dependencies. // Get dependencies.
importPath, err := gf.GetValue("target", "path")
if err != nil {
importPath = "."
}
imports := doc.GetAllImports([]string{curPath}, imports := doc.GetAllImports([]string{curPath},
gf.MustValue("target", "path"), ctx.Bool("example")) importPath, ctx.Bool("example"))
for _, p := range imports { for _, p := range imports {
if _, err := gf.GetValue("deps", doc.GetProjectPath(p)); err != nil { if _, err := gf.GetValue("deps", doc.GetProjectPath(p)); err != nil {

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)

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