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

66 lines
1.1 KiB
Go

package main
import (
"restic"
"restic/errors"
)
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 errors.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 "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 errors.Fatal("invalid type")
}
for id := range repo.List(t, nil) {
cmd.global.Printf("%s\n", id)
}
return nil
}