Example #1
0
File: zenv.go Project: ryo33/zenv
func DoZenv(c *cli.Context) {
	args := c.Args()
	if len(args) == 1 {
		for _, env := range environment.GetActivated(args[0]) {
			util.Print(env)
		}
	} else {
		util.PrintErrorMessage("needs 1 arg")
	}
}
Example #2
0
File: global.go Project: ryo33/zenv
func doGlobal(c *cli.Context) {
	args := c.Args()
	if len(args) == 0 {
		for _, arg := range environment.GetGlovalEnvs() {
			util.Print(arg)
		}
	} else if c.Bool("remove") {
		for _, arg := range args {
			environment.RemoveGlobalEnv(arg)
		}
	} else {
		for _, arg := range args {
			//create new global environment
			env := environment.NewEnv(true, arg, c.Bool("recursive"), c.Bool("exclusive"))
			env.Write()
			env.AddGlobalEnv(c.Bool("force"))
		}
	}
}
Example #3
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 #4
0
File: link.go Project: ryo33/zenv
func doLink(c *cli.Context) {
	args := c.Args()
	if c.Bool("remove") {
		env := GetEnv()
		env.ReadSettings()
		env.RemoveItems("link", removeLink, util.Wrap(args))
		env.Write()
	} else if len(args) == 0 {
		env := GetEnv()
		env.ReadSettings()
		for _, link := range env.GetItems("link") {
			util.Print(link[0] + " " + link[1])
		}
	} else if len(args) != 2 {
		util.PrintArgumentError(2)
	} else {
		env := GetEnv()
		env.ReadSettings()
		env.AddItems("link", c.Bool("force"), []string{args[0], args[1]})
		env.Write()
	}
}
Example #5
0
File: config.go Project: ryo33/zenv
func doConfig(c *cli.Context) {
	args := c.Args()
	argc := len(args)
	Env.ReadSettings()
	// list settings
	if argc == 0 {
		for _, i := range Env.GetItems(GIT_CONFIG) {
			util.Print(strings.Join(i, " "))
		}
	} else if c.Bool("remove") {
		p := [][]string{}
		var global bool
		if c.Bool("global") {
			global = true
		}
		for _, a := range args {
			if global {
				p = append(p, []string{a})
			} else {
				p = append(p, []string{Dir, a})
			}
		}
		Env.RemoveItems(GIT_CONFIG, removeConfig, p)
		Env.Write()
	} else {
		if argc != 2 {
			util.PrintArgumentError(2)
		}
		if c.Bool("global") {
			Env.AddItems(GIT_CONFIG, c.Bool("force"), []string{args[0], args[1]})
		} else {
			Env.AddItems(GIT_CONFIG, c.Bool("force"), []string{Dir, args[0], args[1]})
		}
		Env.Write()
	}
}
Example #6
0
func doCheckout(c *cli.Context) {
	args := c.Args()
	argc := len(args)
	Env.ReadSettings()
	// list settings
	if argc == 0 {
		for _, i := range Env.GetItems(GIT_CHECKOUT) {
			util.Print(strings.Join(i, " "))
		}
	} else if c.Bool("remove") {
		p := [][]string{}
		for _, a := range args {
			p = append(p, []string{util.ExpandPath(a)})
		}
		Env.RemoveItems(GIT_CHECKOUT, remove0, p)
		Env.Write()
	} else {
		if argc != 1 {
			util.PrintArgumentError(1)
		}
		Env.AddItems(GIT_CHECKOUT, c.Bool("force"), []string{Dir, args[0]})
		Env.Write()
	}
}