2014-08-01 22:20:28 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2014-10-05 14:44:59 +02:00
|
|
|
"errors"
|
|
|
|
"fmt"
|
2014-12-21 17:02:49 +01:00
|
|
|
|
2014-12-05 21:45:49 +01:00
|
|
|
"github.com/restic/restic/backend"
|
2014-08-01 22:20:28 +02:00
|
|
|
)
|
|
|
|
|
2014-12-07 16:30:52 +01:00
|
|
|
type CmdList struct{}
|
|
|
|
|
2014-11-30 22:39:58 +01:00
|
|
|
func init() {
|
2014-12-07 16:30:52 +01:00
|
|
|
_, err := parser.AddCommand("list",
|
|
|
|
"lists data",
|
|
|
|
"The list command lists structures or data of a repository",
|
|
|
|
&CmdList{})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2014-11-30 22:39:58 +01:00
|
|
|
}
|
|
|
|
|
2014-12-07 16:30:52 +01:00
|
|
|
func (cmd CmdList) Usage() string {
|
|
|
|
return "[data|trees|snapshots|keys|locks]"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (cmd CmdList) Execute(args []string) error {
|
2014-10-05 14:44:59 +02:00
|
|
|
if len(args) != 1 {
|
2014-12-07 16:30:52 +01:00
|
|
|
return fmt.Errorf("type not specified, Usage: %s", cmd.Usage())
|
|
|
|
}
|
|
|
|
|
2014-12-21 18:10:19 +01:00
|
|
|
s, err := OpenRepo()
|
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
|
|
|
|
2015-02-17 23:05:23 +01:00
|
|
|
var t backend.Type
|
2014-10-05 14:44:59 +02:00
|
|
|
switch args[0] {
|
2014-11-16 13:22:19 +01:00
|
|
|
case "data":
|
|
|
|
t = backend.Data
|
2014-10-05 14:44:59 +02:00
|
|
|
case "trees":
|
|
|
|
t = backend.Tree
|
|
|
|
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
|
|
|
|
2015-03-28 11:50:23 +01:00
|
|
|
for id := range s.List(t, nil) {
|
2015-02-17 23:05:23 +01:00
|
|
|
fmt.Printf("%s\n", id)
|
2015-03-28 11:50:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2014-08-01 22:20:28 +02:00
|
|
|
}
|