Example #1
0
func (c *listCommand) Run() error {
	buckets, err := clibolt.SplitBuckets(c.Arguments.Bucket)
	if err != nil {
		return err
	}
	err = clibolt.Bolt.State.DB.View(func(tx *bolt.Tx) error {
		bucket, err := clibolt.LookupBucket(tx, buckets)
		if err != nil {
			return err
		}
		c := bucket.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			if v == nil {
				// skip buckets
				continue
			}
			_, err := fmt.Println(clibolt.EncodeKey(k))
			if err != nil {
				return err
			}
		}
		return nil
	})
	return err
}
Example #2
0
func (c *putCommand) Run() error {
	buckets, err := clibolt.SplitBuckets(c.Arguments.Bucket)
	if err != nil {
		return err
	}

	key, err := clibolt.DecodeKey(c.Arguments.Key)
	if err != nil {
		return err
	}

	val, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		return err
	}

	err = clibolt.Bolt.State.DB.Update(func(tx *bolt.Tx) error {
		bucket, err := clibolt.LookupBucket(tx, buckets)
		if err != nil {
			return err
		}
		return bucket.Put(key, val)
	})
	if err != nil {
		return err
	}
	return nil
}
Example #3
0
func (c *getCommand) Run() error {
	buckets, err := clibolt.SplitBuckets(c.Arguments.Bucket)
	if err != nil {
		return err
	}

	key, err := clibolt.DecodeKey(c.Arguments.Key)
	if err != nil {
		return err
	}

	var val []byte
	err = clibolt.Bolt.State.DB.View(func(tx *bolt.Tx) error {
		bucket, err := clibolt.LookupBucket(tx, buckets)
		if err != nil {
			return err
		}
		val = bucket.Get(key)
		return nil
	})
	if err != nil {
		return err
	}
	if val == nil {
		return errors.New("database key not found")
	}
	_, err = os.Stdout.Write(val)
	if err != nil {
		return err
	}
	return nil
}
Example #4
0
func (c *bucketsCommand) Run() error {
	if c.Arguments.Bucket == nil {
		return c.runRoot()
	} else {
		buckets, err := clibolt.SplitBuckets(*c.Arguments.Bucket)
		if err != nil {
			return err
		}

		return c.runSub(buckets)
	}
}