示例#1
0
// Which shows which discfg configuration is currently active for use
func Which(opts config.Options) config.ResponseObject {
	resp := config.ResponseObject{
		Action: "which",
	}
	currentCfg := GetDiscfgNameFromFile()
	if currentCfg == "" {
		resp.Error = NoCurrentWorkingCfgMsg
	} else {
		resp.Message = "Current working configuration: " + currentCfg
		resp.CurrentDiscfg = currentCfg
	}
	return resp
}
示例#2
0
// Use sets a discfg configuration to use for all future commands until unset (it is optional, but conveniently saves a CLI argument - kinda like MongoDB's use)
func Use(opts config.Options) config.ResponseObject {
	resp := config.ResponseObject{
		Action: "use",
	}
	if len(opts.CfgName) > 0 {
		cc := []byte(opts.CfgName)
		err := ioutil.WriteFile(".discfg", cc, 0644)
		if err != nil {
			resp.Error = err.Error()
		} else {
			resp.Message = "Set current working discfg to " + opts.CfgName
			resp.CurrentDiscfg = opts.CfgName
		}
	} else {
		resp.Error = NotEnoughArgsMsg
	}
	return resp
}