Example #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)
}
Example #2
0
File: global.go Project: ryo33/zenv
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
		}
	}
}
Example #3
0
File: global.go Project: ryo33/zenv
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)
}
Example #4
0
File: global.go Project: ryo33/zenv
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))
}
Example #5
0
File: io.go Project: 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)
}
Example #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)
		}
	}
}
Example #7
0
func updateLast(key string) {
	if util.Exists(GetStorageDir(TMP, key)) {
		util.WriteFile(getStorageFilePath(TMP, key, LAST), []string{Now()})
	}
}
Example #8
0
File: global.go Project: ryo33/zenv
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))
	}
}