Files
kopia/cli/command_index_list.go
Jarek Kowalski 54edb97b3a refactoring: renamed repo/block to repo/content
Also introduced strongly typed content.ID and manifest.ID (instead of string)

This aligns identifiers across all layers of repository:

blob.ID
content.ID
object.ID
manifest.ID
2019-06-01 22:24:19 -07:00

52 lines
1.2 KiB
Go

package cli
import (
"context"
"fmt"
"sort"
"github.com/kopia/kopia/repo"
)
var (
blockIndexListCommand = indexCommands.Command("list", "List content indexes").Alias("ls").Default()
blockIndexListSummary = blockIndexListCommand.Flag("summary", "Display index blob summary").Bool()
blockIndexListSort = blockIndexListCommand.Flag("sort", "Index blob sort order").Default("time").Enum("time", "size", "name")
)
func runListBlockIndexesAction(ctx context.Context, rep *repo.Repository) error {
blks, err := rep.Content.IndexBlobs(ctx)
if err != nil {
return err
}
switch *blockIndexListSort {
case "time":
sort.Slice(blks, func(i, j int) bool {
return blks[i].Timestamp.Before(blks[j].Timestamp)
})
case "size":
sort.Slice(blks, func(i, j int) bool {
return blks[i].Length < blks[j].Length
})
case "name":
sort.Slice(blks, func(i, j int) bool {
return blks[i].BlobID < blks[j].BlobID
})
}
for _, b := range blks {
fmt.Printf("%-70v %10v %v\n", b.BlobID, b.Length, formatTimestampPrecise(b.Timestamp))
}
if *blockIndexListSummary {
fmt.Printf("total %v blocks\n", len(blks))
}
return nil
}
func init() {
blockIndexListCommand.Action(repositoryAction(runListBlockIndexesAction))
}