restic/src/cmds/restic/cmd_list.go

65 lines
1.0 KiB
Go
Raw Normal View History

2014-08-01 22:20:28 +02:00
package main
2016-09-01 22:17:37 +02:00
import (
"restic"
"restic/errors"
2016-09-17 12:36:05 +02:00
"github.com/spf13/cobra"
2016-09-01 22:17:37 +02:00
)
2014-08-01 22:20:28 +02:00
2016-09-17 12:36:05 +02:00
var cmdList = &cobra.Command{
Use: "list [blobs|packs|index|snapshots|keys|locks]",
Short: "list items in the repository",
Long: `
2014-12-07 16:30:52 +01:00
2016-09-17 12:36:05 +02:00
`,
RunE: func(cmd *cobra.Command, args []string) error {
return runList(globalOptions, args)
},
2014-11-30 22:39:58 +01:00
}
2016-09-17 12:36:05 +02:00
func init() {
cmdRoot.AddCommand(cmdList)
2014-12-07 16:30:52 +01:00
}
2016-09-17 12:36:05 +02:00
func runList(opts GlobalOptions, args []string) error {
2014-10-05 14:44:59 +02:00
if len(args) != 1 {
2016-09-17 12:36:05 +02:00
return errors.Fatalf("type not specified")
2014-12-07 16:30:52 +01:00
}
2016-09-17 12:36:05 +02:00
repo, err := OpenRepository(opts)
2014-12-07 16:30:52 +01:00
if err != nil {
return err
2014-10-05 14:44:59 +02:00
}
2014-08-01 22:20:28 +02:00
2016-09-17 12:36:05 +02:00
if !opts.NoLock {
lock, err := lockRepo(repo)
defer unlockRepo(lock)
if err != nil {
return err
}
2015-06-27 14:40:18 +02:00
}
2016-09-01 16:04:29 +02:00
var t restic.FileType
2014-10-05 14:44:59 +02:00
switch args[0] {
case "packs":
2016-09-01 16:04:29 +02:00
t = restic.DataFile
case "index":
2016-09-01 16:04:29 +02:00
t = restic.IndexFile
2014-10-05 14:44:59 +02:00
case "snapshots":
2016-09-01 16:04:29 +02:00
t = restic.SnapshotFile
2014-10-05 14:44:59 +02:00
case "keys":
2016-09-01 16:04:29 +02:00
t = restic.KeyFile
2014-10-05 14:44:59 +02:00
case "locks":
2016-09-01 16:04:29 +02:00
t = restic.LockFile
2014-10-05 14:44:59 +02:00
default:
2016-09-01 22:17:37 +02:00
return errors.Fatal("invalid type")
2014-10-05 14:44:59 +02:00
}
2014-08-01 22:20:28 +02:00
for id := range repo.List(t, nil) {
2016-09-17 12:36:05 +02:00
Printf("%s\n", id)
2015-03-28 11:50:23 +01:00
}
return nil
2014-08-01 22:20:28 +02:00
}