1
0
mirror of https://github.com/restic/restic.git synced 2024-06-22 07:26:38 +02:00
restic/cmd/khepri/cmd_list.go

45 lines
887 B
Go
Raw Normal View History

2014-08-01 22:20:28 +02:00
package main
import (
2014-10-05 14:44:59 +02:00
"errors"
"fmt"
2014-08-01 22:20:28 +02:00
"github.com/fd0/khepri"
2014-09-23 22:39:12 +02:00
"github.com/fd0/khepri/backend"
2014-08-01 22:20:28 +02:00
)
2014-09-23 22:39:12 +02:00
func commandList(be backend.Server, key *khepri.Key, args []string) error {
2014-10-05 14:44:59 +02:00
if len(args) != 1 {
return errors.New("usage: list [blobs|trees|snapshots|keys|locks]")
}
2014-08-01 22:20:28 +02:00
2014-10-05 14:44:59 +02:00
var (
t backend.Type
each func(backend.Server, backend.Type, func(backend.ID, []byte, error)) error = backend.Each
)
switch args[0] {
case "blobs":
t = backend.Blob
each = key.Each
case "trees":
t = backend.Tree
each = key.Each
case "snapshots":
t = backend.Snapshot
case "keys":
t = backend.Key
case "locks":
t = backend.Lock
default:
return errors.New("invalid type")
}
2014-08-01 22:20:28 +02:00
2014-10-05 14:44:59 +02:00
return each(be, t, func(id backend.ID, data []byte, err error) {
if t == backend.Blob || t == backend.Tree {
fmt.Printf("%s %s\n", id, backend.Hash(data))
} else {
fmt.Printf("%s\n", id)
}
})
2014-08-01 22:20:28 +02:00
}