Browse Source

Improved gopm bin

pull/103/head
Unknown 11 years ago
parent
commit
23ce93ab24
  1. 53
      cmd/bin.go
  2. 9
      cmd/build.go
  3. 2
      cmd/get.go
  4. 2
      gopm.go

53
cmd/bin.go

@ -39,17 +39,17 @@ gopm bin <import path>@[<tag|commit|branch>:<value>]
gopm bin <package name>@[<tag|commit|branch>:<value>]
Can only specify one each time, and only works for projects that
contains main package`,
contain 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"},
cli.BoolFlag{"update, u", "update pakcage(s) and dependencies if any"},
cli.BoolFlag{"verbose, v", "show process details"},
},
}
func runBin(ctx *cli.Context) {
log.PureMode = ctx.GlobalBool("noterm")
log.Verbose = ctx.GlobalBool("verbose")
setup(ctx)
if len(ctx.Args()) == 0 {
log.Error("bin", "Cannot start command:")
@ -57,6 +57,7 @@ func runBin(ctx *cli.Context) {
}
installRepoPath = doc.HomeDir + "/repos"
log.Log("Local repository path: %s", installRepoPath)
// Check arguments.
num := 1
@ -77,11 +78,11 @@ func runBin(ctx *cli.Context) {
// Parse package version.
info := ctx.Args()[0]
pkgPath := info
ver := ""
tp, ver := "", ""
var err error
if i := strings.Index(info, "@"); i > -1 {
pkgPath = info[:i]
_, ver = validPath(info[i+1:])
tp, ver = validPath(info[i+1:])
}
// Check package name.
@ -89,24 +90,10 @@ func runBin(ctx *cli.Context) {
pkgPath = doc.GetPkgFullPath(pkgPath)
}
node := doc.NewNode(pkgPath, pkgPath, tp, ver, true)
// Get code.
args := make([]string, 0, 4)
if log.PureMode {
args = append(args, "-noterm")
}
args = append(args, []string{"get", "-r", ctx.Args()[0]}...)
stdout, stderr, err := com.ExecCmd("gopm", args...)
if err != nil {
log.Error("bin", "Error occurs when 'gopm get -r':")
log.Fatal("", "\r"+err.Error())
}
if len(stderr) > 0 {
log.Error("bin", "Fail to 'gopm get -r':")
log.Fatal("", "\r"+stderr)
}
if len(stdout) > 0 {
fmt.Print(stdout)
}
downloadPackages(ctx, []*doc.Node{node})
// Check if previous steps were successful.
repoPath := installRepoPath + "/" + pkgPath + versionSuffix(ver)
@ -130,26 +117,10 @@ func runBin(ctx *cli.Context) {
}
// Build application.
args = make([]string, 0, 2)
if log.PureMode {
args = append(args, "-noterm")
}
args = append(args, "build")
stdout, stderr, err = com.ExecCmd("gopm", args...)
if err != nil {
log.Error("bin", "Error occurs when 'gopm build':")
log.Fatal("", "\r"+err.Error())
}
if len(stderr) > 0 {
log.Error("bin", "Fail to 'gopm build':")
log.Fatal("", "\r"+stderr)
}
if len(stdout) > 0 {
fmt.Print(stdout)
}
buildBinary(ctx)
defer func() {
// Clean files.
//os.RemoveAll(path.Join(repoPath, doc.VENDOR))
os.RemoveAll(path.Join(repoPath, doc.VENDOR))
}()
// Check if previous steps were successful.

9
cmd/build.go

@ -54,12 +54,17 @@ func runBuild(ctx *cli.Context) {
installGopath += "/src"
}
buildBinary(ctx, ctx.Args()...)
log.Success("SUCC", "build", "Command executed successfully!")
}
func buildBinary(ctx *cli.Context, args ...string) {
genNewGoPath(ctx, false)
log.Trace("Building...")
cmdArgs := []string{"go", "build"}
cmdArgs = append(cmdArgs, ctx.Args()...)
cmdArgs = append(cmdArgs, args...)
err := execCmd(newGoPath, newCurPath, cmdArgs...)
if err != nil {
log.Error("build", "fail to build program:")
@ -79,6 +84,4 @@ func runBuild(ctx *cli.Context) {
log.Warn("No binary generated")
}
}
log.Success("SUCC", "build", "Command executed successfully!")
}

2
cmd/get.go

@ -187,7 +187,7 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) {
installPath := path.Join(installRepoPath, n.RootPath) +
versionSuffix(n.Value)
if !ctx.Bool("force") {
if !ctx.Bool("update") {
// Check if package has been downloaded.
if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) ||
com.IsExist(installPath) {

2
gopm.go

@ -29,7 +29,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true
const APP_VER = "0.6.0.1206.1"
const APP_VER = "0.6.0.1206.2"
// //cmd.CmdSearch,
// cmdClean,

Loading…
Cancel
Save