mirror of
https://github.com/kopia/kopia.git
synced 2026-03-12 03:06:31 -04:00
added 'manifest ls' subcommand
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
snapshotCommands = app.Command("snapshot", "Commands to manipulate snapshots.").Alias("snap")
|
||||
policyCommands = app.Command("policy", "Commands to manipulate snapshotting policies.").Alias("policies")
|
||||
metadataCommands = app.Command("metadata", "Low-level commands to manipulate metadata items.").Alias("md")
|
||||
manifestCommands = app.Command("manifest", "Low-level commands to manipulate manifest items.")
|
||||
objectCommands = app.Command("object", "Commands to manipulate objects in repository.").Alias("obj")
|
||||
blockCommands = app.Command("block", "Commands to manipulate blocks in repository.").Alias("blk")
|
||||
blockIndexCommands = blockCommands.Command("index", "Commands to manipulate block indexes.")
|
||||
|
||||
53
cli/command_manifest_ls.go
Normal file
53
cli/command_manifest_ls.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
var (
|
||||
manifestListCommand = manifestCommands.Command("list", "List manifest items").Alias("ls").Hidden()
|
||||
manifestListPrefix = manifestListCommand.Flag("prefix", "Prefix").String()
|
||||
)
|
||||
|
||||
func init() {
|
||||
manifestListCommand.Action(listManifestItems)
|
||||
}
|
||||
|
||||
func listManifestItems(context *kingpin.ParseContext) error {
|
||||
rep := mustOpenRepository(nil)
|
||||
|
||||
items := rep.Manifests.Find(nil)
|
||||
|
||||
for _, id := range items {
|
||||
var data map[string]interface{}
|
||||
|
||||
labels, err := rep.Manifests.Get(id, &data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
t := labels["type"]
|
||||
delete(labels, "type")
|
||||
|
||||
fmt.Printf("%v %v\n", id, t)
|
||||
for _, k := range sortedMapKeys(labels) {
|
||||
fmt.Printf(" %v: %v\n", k, labels[k])
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func sortedMapKeys(m map[string]string) []string {
|
||||
var result []string
|
||||
|
||||
for k := range m {
|
||||
result = append(result, k)
|
||||
}
|
||||
|
||||
sort.Strings(result)
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user