Exemple #1
0
func deleteBuckets(root bucket.Bucket, names []string) error {
	_, children, err := root.List()
	if err != nil {
		return fmt.Errorf("List: %s", err)
	}
	childMap := make(map[string]bool)
	for _, child := range children {
		childMap[child] = true
	}

	for _, name := range names {
		if _, ok := childMap[name]; !ok {
			fmt.Printf("\n%q not found. Skipping.\n", name)
			continue
		}

		child, err := root.Descend(name)
		if err != nil {
			return fmt.Errorf("Descend(%q): %s", name, err)
		}

		keys, children, err := child.List()
		if err != nil {
			return fmt.Errorf("List: %s", err)
		}

		fmt.Printf("\nGoing to delete %q:\n", name)
		for _, s := range summary(keys) {
			fmt.Println("  ", s)
		}
		for _, s := range summary(children) {
			fmt.Println("  ", s)
		}
		fmt.Printf("Continue? [y/N]: ")

		buf := bufio.NewReader(os.Stdin)
		line, err := buf.ReadString('\n')
		if err != nil {
			return fmt.Errorf("ReadString: %s", err)
		}
		if line == "" || (line[0] != 'y' && line[0] != 'Y') {
			fmt.Println("Delete cancelled!")
			return nil
		}

		err = child.Destroy()
		if err != nil {
			return fmt.Errorf("Destroy: %s", err)
		}

		fmt.Printf("Deleted %q\n", name)
	}
	return nil
}
Exemple #2
0
func (c *Command) Run(b bucket.Bucket) (int64, error) {
	childName := c.args[0]
	child, err := b.Descend(childName)
	if err != nil {
		return 0, fmt.Errorf("error descending into bucket %q: %s", childName, err)
	}

	switch c.kind {
	case cmdPut:
		return kebab.Put(child, "", c.args[1:])
	case cmdPutFrom:
		return kebab.Put(child, c.args[1], c.args[2:])
	case cmdGet:
		return kebab.Get(child, childName)
	default:
		return 0, fmt.Errorf("unexpected command type: %d", c.kind)
	}
}