2
2
mirror of https://github.com/octoleo/restic.git synced 2024-09-27 05:59:01 +00:00
restic/cmd/restic/cmd_list.go

58 lines
903 B
Go
Raw Normal View History

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