示例#1
0
文件: install.go 项目: Andals/gpm
func (this *installCommand) Run(prjHome string, logger log.ILogger) *exception.Exception {
	pkgConf, err := pconf.ParsePackageConf(prjHome)
	if err != nil {
		logger.Debug([]byte(err.Msg() + "\n"))

		return err
	}

	logger.Debug([]byte("Remove vender root\n"))
	os.RemoveAll(pconf.GetVendorRoot(prjHome))

	dependencies := pkgConf.GetDependencies()
	for name, depConf := range dependencies {
		goSrcRoot := os.Getenv("GOPATH") + "/src"
		if misc.DirExist(goSrcRoot + "/" + name) {
			logger.Warning(color.Red([]byte("There is " + name + " in go src root\n")))
		}

		logger.Info([]byte("Start install " + name + "\n"))

		path := depConf.GetPath()
		repConf := depConf.GetRepository()

		pkgLevelDir := path.GetLevelDir()
		pkgBaseDir := path.GetBaseDir()
		pkgPrjHome := pkgLevelDir + "/" + pkgBaseDir

		os.MkdirAll(pkgLevelDir, 0755)

		cmd := "cd " + pkgLevelDir + ";"
		cmd += "git clone " + repConf.GetUrl() + " " + pkgBaseDir + ";"
		cmd += "cd " + pkgBaseDir + ";"

		tag := repConf.GetTag()
		if tag != "" {
			cmd += "git checkout " + tag + " -b " + tag + ";"
		}
		cmd += "rm -rf .git; 2>&1"

		result := shell.RunCmd(cmd)
		logger.Debug([]byte(result.Output))

		command := new(installCommand)
		command.Run(pkgPrjHome, logger)

		logger.Info([]byte("End install " + name + "\n"))
	}

	return nil
}
示例#2
0
文件: main.go 项目: Andals/gpm-demo
func main() {
	result := shell.RunCmd("ls -al")

	fmt.Println(result)
}