Beispiel #1
0
func WriteStorage(name, key, subkey string, data []string) {
	if len(name) == 0 {
		name = STORAGE
	}
	util.PrepareDir(GetStorageDir(name, key))
	util.WriteFile(getStorageFilePath(name, key, subkey), data)
}
Beispiel #2
0
func removeEnvDir(name string) {
	dirs := getEnvDirs()
	for i, dir := range dirs {
		if name == dir {
			util.WriteFile(path.Join(util.GetHomeDir(), zenv.ZENV, DIRS), append(dirs[:i], dirs[i+1:]...))
			return
		}
	}
}
Beispiel #3
0
func RemoveGlobalEnv(name string) {
	envFile := GetEnvsPath()
	tmp := util.ReadFile(envFile)
	result := []string{}
	for _, en := range tmp {
		if en != name {
			result = append(result, en)
		}
	}
	util.WriteFile(envFile, result)
}
Beispiel #4
0
func (env *Env) AddGlobalEnv(force bool) {
	envFile := GetEnvsPath()
	tmp := util.ReadFile(envFile)
	for _, en := range tmp {
		if en == env.name {
			if !force {
				util.PrintErrorMessage("already exists\n--force to overwrite") //TODO already exists  --force to overwrite
			}
			break
		}
	}
	util.WriteFile(envFile, append(tmp, env.name))
}
Beispiel #5
0
Datei: io.go Projekt: ryo33/zenv
//write info
func (env *Env) writeInfo() {
	info := append([]string{}, "name"+SEPARATOR+env.name, "dir"+SEPARATOR+env.dir)
	if env.global {
		info = append(info, "global"+SEPARATOR+"true")
	} else {
		info = append(info, "global"+SEPARATOR+"false")
	}
	if env.recursive {
		info = append(info, "recursive"+SEPARATOR+"true")
	} else {
		info = append(info, "recursive"+SEPARATOR+"false")
	}
	if env.exclusive {
		info = append(info, "exclusive"+SEPARATOR+"true")
	} else {
		info = append(info, "exclusive"+SEPARATOR+"false")
	}
	util.WriteFile(path.Join(env.dir, INFO), info)
}
Beispiel #6
0
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)
		}
	}
}
Beispiel #7
0
func updateLast(key string) {
	if util.Exists(GetStorageDir(TMP, key)) {
		util.WriteFile(getStorageFilePath(TMP, key, LAST), []string{Now()})
	}
}
Beispiel #8
0
func (env *Env) addEnvDir() {
	dirs := getEnvDirs()
	if !util.Contains(dirs, env.name) {
		util.WriteFile(path.Join(util.GetHomeDir(), zenv.ZENV, DIRS), append(dirs, env.name))
	}
}