From 5cbd1d0090621e16d36ff5fe69a40d7492f5e746 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 1 Aug 2014 22:20:28 +0200 Subject: [PATCH] Add command 'list' --- cmd/khepri/cmd_list.go | 29 +++++++++++++++++++++++++++++ cmd/khepri/main.go | 1 + 2 files changed, 30 insertions(+) create mode 100644 cmd/khepri/cmd_list.go diff --git a/cmd/khepri/cmd_list.go b/cmd/khepri/cmd_list.go new file mode 100644 index 000000000..5cbb91a9b --- /dev/null +++ b/cmd/khepri/cmd_list.go @@ -0,0 +1,29 @@ +package main + +import ( + "errors" + "fmt" + "os" + + "github.com/fd0/khepri" +) + +func commandList(repo *khepri.DirRepository, args []string) error { + if len(args) != 1 { + return errors.New("usage: list [blob|ref]") + } + + tpe := khepri.NewTypeFromString(args[0]) + + ids, err := repo.ListIDs(tpe) + if err != nil { + fmt.Fprintf(os.Stderr, "error: %v\n", err) + return nil + } + + for _, id := range ids { + fmt.Printf("%v\n", id) + } + + return nil +} diff --git a/cmd/khepri/main.go b/cmd/khepri/main.go index e23490d6e..d659b8f5c 100644 --- a/cmd/khepri/main.go +++ b/cmd/khepri/main.go @@ -30,6 +30,7 @@ func init() { commands = make(map[string]commandFunc) commands["backup"] = commandBackup commands["restore"] = commandRestore + commands["list"] = commandList } func main() {