Example #1
0
File: cmd.go Project: nashtsai/gopm
// validPath checks if the information of the package is valid.
func validPath(info string) (string, string) {
	infos := strings.Split(info, ":")

	l := len(infos)
	switch {
	case l == 1:
		// for local imports
		if com.IsFile(infos[0]) {
			return doc.LOCAL, infos[0]
		}

		return doc.BRANCH, ""
	case l == 2:
		switch infos[1] {
		case doc.TRUNK, doc.MASTER, doc.DEFAULT:
			infos[1] = ""
		}
		return infos[0], infos[1]
	default:
		log.Error("", "Cannot parse dependency version:")
		log.Error("", "\t"+info)
		log.Help("Try 'gopm help get' to get more information")
		return "", ""
	}
}
Example #2
0
File: get.go Project: nashtsai/gopm
func runGet(ctx *cli.Context) {
	setup(ctx)

	// Check conflicts.
	if ctx.Bool("gopath") && ctx.Bool("remote") {
		log.Error("get", "Command options have conflicts")
		log.Error("", "Following options are not supposed to use at same time:")
		log.Error("", "\t'--gopath, -g' '--remote, -r'")
		log.Help("Try 'gopm help get' to get more information")
	}

	if !ctx.Bool("remote") {
		// Get GOPATH.
		installGopath = com.GetGOPATHs()[0]
		if com.IsDir(installGopath) {
			isHasGopath = true
			log.Log("Indicated GOPATH: %s", installGopath)
			installGopath += "/src"
		} else {
			if ctx.Bool("gopath") {
				log.Error("get", "Invalid GOPATH path")
				log.Error("", "GOPATH does not exist or is not a directory:")
				log.Error("", "\t"+installGopath)
				log.Help("Try 'go help gopath' to get more information")
			} else {
				// It's OK that no GOPATH setting
				// when user does not specify to use.
				log.Warn("No GOPATH setting available")
			}
		}
	}

	// The gopm local repository.
	installRepoPath = doc.HomeDir + "/repos"
	log.Log("Local repository path: %s", installRepoPath)

	// Check number of arguments to decide which function to call.
	switch len(ctx.Args()) {
	case 0:
		getByGopmfile(ctx)
	default:
		getByPath(ctx)
	}
}
Example #3
0
func runInstall(ctx *cli.Context) {
	setup(ctx)

	var target string
	switch len(ctx.Args()) {
	case 0:
		if !com.IsFile(".gopmfile") {
			break
		}

		gf := doc.NewGopmfile(".")
		target = gf.MustValue("target", "path")
	case 1:
		target = ctx.Args()[0]
	default:
		log.Fatal("install", "Too many arguments")
	}

	// Get GOPATH.
	installGopath = com.GetGOPATHs()[0]
	if com.IsDir(installGopath) {
		isHasGopath = true
		log.Log("Indicated GOPATH: %s", installGopath)
		installGopath += "/src"
	} else {
		if ctx.Bool("gopath") {
			log.Error("get", "Invalid GOPATH path")
			log.Error("", "GOPATH does not exist or is not a directory:")
			log.Error("", "\t"+installGopath)
			log.Help("Try 'go help gopath' to get more information")
		} else {
			// It's OK that no GOPATH setting
			// when user does not specify to use.
			log.Warn("No GOPATH setting available")
		}
	}

	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, repo)
		err := execCmd(newGoPath, newCurPath, cmdArgs...)
		if err != nil {
			log.Error("install", "Fail to install program:")
			log.Fatal("", "\t"+err.Error())
		}
	}

	log.Success("SUCC", "install", "Command executed successfully!")
}
Example #4
0
File: get.go Project: kulasama/gopm
func runGet(ctx *cli.Context) {
	setup(ctx)
	// Check conflicts.
	if ctx.Bool("gopath") && ctx.Bool("remote") ||
		ctx.Bool("local") && ctx.Bool("remote") ||
		ctx.Bool("gopath") && ctx.Bool("local") {
		e := " "
		if ctx.Bool("gopath") {
			e += "--gopth,-g "
		}
		if ctx.Bool("remote") {
			e += "--remote,-r "
		}
		if ctx.Bool("local") {
			e += "--local,-l "
		}
		log.Error("get", "Command options have conflicts")
		log.Error("", "Following options are not supposed to use at same time:")
		log.Error("", "\t"+e)
		log.Help("Try 'gopm help get' to get more information")
	}

	if !ctx.Bool("remote") {
		// Get GOPATH.
		installGopath = com.GetGOPATHs()[0]
		if com.IsDir(installGopath) {
			isHasGopath = true
			log.Log("Indicated GOPATH: %s", installGopath)
			installGopath += "/src"
		} else {
			if ctx.Bool("gopath") {
				log.Error("get", "Invalid GOPATH path")
				log.Error("", "GOPATH does not exist or is not a directory:")
				log.Error("", "\t"+installGopath)
				log.Help("Try 'go help gopath' to get more information")
			} else {
				// It's OK that no GOPATH setting
				// when user does not specify to use.
				log.Warn("No GOPATH setting available")
			}
		}
		// if flag local set use localPath as GOPATH
		if ctx.Bool("local") {
			if !com.IsExist(".gopmfile") {
				runGen(ctx)
			}
			gf, err := goconfig.LoadConfigFile(".gopmfile")
			if err != nil {
				log.Fatal("get", err.Error())
			} else {
				installGopath = gf.MustValue("project", "localPath")
				if installGopath == "" {
					os.Remove(".gopmfile")
					log.Fatal("get", "unexpected localPath or no localPath exists")
				}
				installGopath += "/src"
			}
		}
	}

	// The gopm local repository.
	installRepoPath = path.Join(doc.HomeDir, "repos")
	log.Log("Local repository path: %s", installRepoPath)

	// Check number of arguments to decide which function to call.
	switch len(ctx.Args()) {
	case 0:
		getByGopmfile(ctx)
	case 1:
		getByPath(ctx)
	default:
		log.Error("get", "too many arguments")
		log.Help("Try 'gopm help get' to get more information")
	}
}