コード例 #1
0
ファイル: git.go プロジェクト: ryo33/zenv
func beforeGit(c *cli.Context) error {
	if dir := c.String("directory"); len(dir) > 0 {
		git.Dir = util.ExpandPath(dir)
	} else {
		git.Dir = util.GetCurrentPath()
	}
	git.Env = GetEnv()
	return nil
}
コード例 #2
0
ファイル: local.go プロジェクト: ryo33/zenv
func doLocal(c *cli.Context) {
	pwd := util.GetCurrentPath()
	if environment.ExistsLocalEnv(pwd) && !c.Bool("force") {
		util.PrintErrorMessage(fmt.Sprintf("%s already exists\n--force flag to force to initialize", environment.ZENV_LOCAL))
	} else {
		env := environment.NewEnv(false, pwd, !c.Bool("not-recursive"), c.Bool("exclusive"))
		env.Write()
	}
}
コード例 #3
0
ファイル: git_config.go プロジェクト: ryo33/zenv
func activateGitConfig(args []string, info *Info) bool {
	var global bool
	var dir, gitDir, name, value string
	if len(args) == 2 {
		global = true
		dir = util.GetCurrentPath()
		name = args[0]
		value = args[1]
	} else if len(args) == 3 {
		dir = args[0]
		name = args[1]
		value = args[2]
	} else {
		return false
	}
	gitDir = getGitDir(dir)

	var preValue string
	var err error
	if global {
		preValue, err = util.ExecCommand("git", "config", "--global", name)
	} else {
		preValue, err = util.ExecCommand("git", gitDir, "config", name)
	}
	if err != nil {
		util.PrintErrorMessageContinue(fmt.Sprintf("can't change config %s to %s in %s", name, value, dir))
		return false
	}
	escapedDir := escapeDir(dir)
	values := storage.ReadStorage(SETTINGS, GIT_CONFIG, escapedDir)
	storage.WriteStorage(SETTINGS, GIT_CONFIG, escapedDir, append(values, info.envdir+"="+preValue))
	if global {
		_, err = util.ExecCommand("git", "config", "--global", name, value)
	} else {
		_, err = util.ExecCommand("git", gitDir, "config", name, value)
	}
	if err != nil {
		util.PrintErrorMessageContinue(fmt.Sprintf("can't change config %s to %s in %s", name, value, dir))
		return false
	}
	return true
}
コード例 #4
0
ファイル: environment.go プロジェクト: ryo33/zenv
func GetCurrentEnv() *Env {
	return read(getLocalPath(util.GetCurrentPath()))
}