2
2
mirror of https://github.com/octoleo/restic.git synced 2024-05-28 14:40:49 +00:00
restic/src/cmds/restic/cmd_list.go
2016-09-03 21:10:24 +02:00

77 lines
1.3 KiB
Go

package main
import "restic"
type CmdList struct {
global *GlobalOptions
}
func init() {
_, err := parser.AddCommand("list",
"lists data",
"The list command lists structures or data of a repository",
&CmdList{global: &globalOpts})
if err != nil {
panic(err)
}
}
func (cmd CmdList) Usage() string {
return "[blobs|packs|index|snapshots|keys|locks]"
}
func (cmd CmdList) Execute(args []string) error {
if len(args) != 1 {
return restic.Fatalf("type not specified, Usage: %s", cmd.Usage())
}
repo, err := cmd.global.OpenRepository()
if err != nil {
return err
}
if !cmd.global.NoLock {
lock, err := lockRepo(repo)
defer unlockRepo(lock)
if err != nil {
return err
}
}
var t restic.FileType
switch args[0] {
// case "blobs":
// restic.Lister
// err = repo.LoadIndex()
// if err != nil {
// return err
// }
// for _, idx := range repo.Index().All() {
// for blob := range idx.Each(nil) {
// cmd.global.Printf("%s\n", blob.ID)
// }
// }
// return nil
case "packs":
t = restic.DataFile
case "index":
t = restic.IndexFile
case "snapshots":
t = restic.SnapshotFile
case "keys":
t = restic.KeyFile
case "locks":
t = restic.LockFile
default:
return restic.Fatal("invalid type")
}
for id := range repo.List(t, nil) {
cmd.global.Printf("%s\n", id)
}
return nil
}