Esempio n. 1
0
// 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
		}
	}
}
Esempio n. 2
0
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)
		}
	}
}
Esempio n. 3
0
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
		}
	}
}
Esempio n. 4
0
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))
		}
	}
}
Esempio n. 5
0
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))
	}
}