restic/cmd/restic/cmd_list.go

51 lines
972 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-12-05 21:45:49 +01:00
"github.com/restic/restic"
"github.com/restic/restic/backend"
2014-08-01 22:20:28 +02:00
)
2014-11-30 22:39:58 +01:00
func init() {
commands["list"] = commandList
}
2014-12-05 21:45:49 +01:00
func commandList(be backend.Server, key *restic.Key, args []string) error {
2014-10-05 14:44:59 +02:00
if len(args) != 1 {
return errors.New("usage: list [data|trees|snapshots|keys|locks]")
2014-10-05 14:44:59 +02:00
}
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 "data":
t = backend.Data
2014-10-05 14:44:59 +02:00
each = key.Each
case "trees":
t = backend.Tree
each = key.Each
case "snapshots":
t = backend.Snapshot
2014-11-23 23:29:29 +01:00
case "maps":
t = backend.Map
2014-10-05 14:44:59 +02:00
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.Data || t == backend.Tree {
2014-10-05 14:44:59 +02:00
fmt.Printf("%s %s\n", id, backend.Hash(data))
} else {
fmt.Printf("%s\n", id)
}
})
2014-08-01 22:20:28 +02:00
}