示例#1
0
文件: settings.go 项目: ryo33/zenv
func (items Items) Deactivate(info *Info) {
	for key, its := range items.ToMap() {
		se, ok := settings[key]
		if !ok {
			util.PrintErrorMessageContinue(key + " lable is undefined")
		} else {
			for _, it := range its {
				if !se.deactivate(it, info) {
					util.PrintErrorMessageContinue("can't deactivate")
				}
			}
		}
	}
}
示例#2
0
文件: settings.go 项目: ryo33/zenv
func (items Items) AddItems(lable string, force bool, its2 [][]string) {
	its, ok := items.ToMap()[lable]
	se, ok2 := settings[lable]
	if !ok {
		its = [][]string{}
	}
	if !ok2 {
		util.PrintErrorMessageContinue(lable + " lable is undefined")
	} else {
		for idx, it := range its {
			tmp := its2
			for idx2, it2 := range tmp {
				if se.equal(it, it2) {
					if !force {
						util.PrintErrorMessage(strings.Join(it2, " ") + " already exists\n--force to overwrite")
					} else {
						items.ToMap()[lable][idx] = it2
					}
					its2 = append(its2[:idx2], its2[idx2+1:]...)
				}
			}
		}
		items.ToMap()[lable] = append(its, its2...)
	}
}
示例#3
0
文件: global.go 项目: ryo33/zenv
func getEnvs(dir string) []*Env {
	tmp := getEnvDirs()
	dirs := []string{}
	for _, tmpDir := range tmp {
		if strings.HasPrefix(dir, tmpDir) {
			dirs = append(dirs, tmpDir)
		}
	}
	sort.Sort(ByLength(dirs))
	envs := []*Env{}
	for i := len(dirs) - 1; i >= 0; i-- {
		name := dirs[i]
		var env = getLocalEnv(name)
		if env != nil {
			if dirs[i] == dir {
				envs = append(envs, env)
			} else if env.recursive {
				envs = append(envs, env)
			}
			if env.exclusive {
				break
			}
		} else {
			util.PrintErrorMessageContinue(fmt.Sprintf("%s not exists", name))
			if util.YNPrompt("remove?", false) {
				removeEnvDir(name)
			}
		}
	}
	return envs
}
示例#4
0
func activateGitCheckout(args []string, info *Info) bool {
	if len(args) != 2 {
		return false
	}
	branch, err := util.ExecCommand("git", getGitDir(args[0]), "rev-parse", "--abbrev-ref", "HEAD")
	if err != nil || len(branch) == 0 {
		util.PrintErrorMessageContinue("can't find branch message in " + args[0])
		return false
	}
	dir := escapeDir(args[0])
	branches := storage.ReadStorage(SETTINGS, GIT_CHECKOUT, dir)
	storage.WriteStorage(SETTINGS, GIT_CHECKOUT, dir, append(branches, info.envdir+"="+branch))
	_, err = util.ExecCommand("git", getGitDir(args[0]), "checkout", args[1])
	if err != nil {
		util.PrintErrorMessageContinue(fmt.Sprintf("can't checkout to %s in %s", args[1], args[0]))
		return false
	}
	return true
}
示例#5
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
}
示例#6
0
文件: settings.go 项目: ryo33/zenv
func (items Items) Clean(info *Info) {
	newItems := make(map[string][][]string)
	for key, its := range items.ToMap() {
		se, ok := settings[key]
		if !ok {
			util.PrintErrorMessageContinue(key + " lable is undefined")
		} else if se.mustDeactivate {
			newItems[key] = its
		}
	}
	Items(newItems).Deactivate(info)
}
示例#7
0
文件: settings.go 项目: ryo33/zenv
func (items Items) Write(dir string) {
	// each lables
	for key, its := range items.ToMap() {
		result := []string{}
		se, ok := settings[key]
		if !ok {
			util.PrintErrorMessageContinue(key + " lable is undefined")
		}
		for _, it := range its {
			if str := se.write(it); len(str) > 0 {
				result = append(result, str)
			} else {
				util.Print("黄金") // This should not be called.
			}
		}
		if len(result) > 0 {
			util.WriteFile(path.Join(dir, key), result)
		}
	}
}