示例#1
0
文件: mkdir.go 项目: JeffChien/kvctl
// only available in etcd
func (m *MkdirCommand) run(c *cli.Context) {
	kv, err := storage.New(c.GlobalString("backend"))
	if err != nil {
		fmt.Println(err)
		return
	}
	if len(c.Args()) == 0 {
		fmt.Println(fmt.Errorf("at leat one path"))
		return
	}
	cmd, ok := kv.(lib.Command)
	if !ok {
		fmt.Println("not a command")
		return
	}
	for _, v := range c.Args() {
		err := cmd.Mkdir(v, &lib.MkdirOption{
			Parent: c.Bool("parent"),
		})
		if err != nil {
			fmt.Println(lib.PrefixError(v, err))
			continue
		}
	}
}
示例#2
0
文件: ls.go 项目: JeffChien/kvctl
func (m *LsCommand) run(c *cli.Context) {
	var paths []string = []string(c.Args())
	kv, err := storage.New(c.GlobalString("backend"))
	if err != nil {
		fmt.Println(err)
		return
	}
	if !c.Args().Present() {
		paths = append(paths, "")
	}
	cmd, ok := kv.(lib.Command)
	if !ok {
		fmt.Println("not a command")
		return
	}
	for _, v := range paths {
		pairs, err := cmd.Ls(v)
		if err != nil && v != "" {
			fmt.Println(lib.PrefixError(v, err))
			continue
		}
		sort.Sort(byDictionary(pairs))
		for _, vv := range pairs {
			fmt.Println(vv.Key)
		}
	}
}
示例#3
0
文件: touch.go 项目: JeffChien/kvctl
func (m *TouchCommand) run(c *cli.Context) {
	var data []byte
	kv, err := storage.New(c.GlobalString("backend"))
	if err != nil {
		fmt.Println(err)
		return
	}
	if len(c.Args()) == 0 {
		fmt.Println(fmt.Errorf("at leat one path"))
		return
	}

	if terminal.IsTerminal(int(os.Stdin.Fd())) {
		// nothing on stdin
		data = []byte("")
	} else {
		// something on stdin
		data, err = ioutil.ReadAll(os.Stdin)
		if err != nil {
			fmt.Println(err)
			return
		}
	}

	cmd, ok := kv.(lib.Command)
	if !ok {
		fmt.Println("not a command")
		return
	}

	for _, v := range c.Args() {
		err := cmd.Touch(v, data, nil)
		if err != nil {
			fmt.Println(lib.PrefixError(v, err))
			continue
		}
	}
}
示例#4
0
文件: rm.go 项目: JeffChien/kvctl
func (m *RmCommand) run(c *cli.Context) {
	kv, err := storage.New(c.GlobalString("backend"))
	if err != nil {
		fmt.Println(err)
		return
	}
	paths := []string{}
	if len(c.Args()) == 0 {
		paths = append(paths, "")
	} else {
		paths = append(paths, c.Args()...)
	}
	cmd, ok := kv.(lib.Command)
	if !ok {
		fmt.Println("not a command")
		return
	}
	for _, v := range paths {
		err = cmd.Rm(v, c.Bool("recursive"))
		if err != nil {
			fmt.Println(lib.PrefixError(v, err))
		}
	}
}
示例#5
0
文件: cat.go 项目: JeffChien/kvctl
func (m *CatCommand) run(c *cli.Context) {
	kv, err := storage.New(c.GlobalString("backend"))
	if err != nil {
		fmt.Println(err)
		return
	}
	if len(c.Args()) == 0 {
		fmt.Println(fmt.Errorf("at leat one path"))
		return
	}
	cmd, ok := kv.(lib.Command)
	if !ok {
		fmt.Println("not a command")
		return
	}
	for _, v := range c.Args() {
		pair, err := cmd.Cat(v)
		if err != nil {
			fmt.Println(lib.PrefixError(v, err))
			continue
		}
		fmt.Println(string(pair.Value))
	}
}