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 }
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 }
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 }
func (c *bucketsCommand) runSub(buckets [][]byte) error { 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 { // not a bucket continue } _, err := fmt.Println(clibolt.EncodeKey(k)) if err != nil { return err } } return nil }) return err }