diff --git a/cmd/bin.go b/cmd/bin.go index 9ee1007a4..1910824ba 100644 --- a/cmd/bin.go +++ b/cmd/bin.go @@ -39,17 +39,17 @@ gopm bin @[:] gopm bin @[:] 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. diff --git a/cmd/build.go b/cmd/build.go index 155e00880..6b635da67 100644 --- a/cmd/build.go +++ b/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!") } diff --git a/cmd/get.go b/cmd/get.go index f96dae1b0..31668fdd5 100644 --- a/cmd/get.go +++ b/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) { diff --git a/gopm.go b/gopm.go index 86008f894..c9604a44c 100644 --- a/gopm.go +++ b/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,