mirror of
https://github.com/kopia/kopia.git
synced 2025-12-23 22:57:50 -05:00
* breaking(cli): remove default behavior for `snapshot` command command: snapshot default-subcommand: create * breaking(cli): remove default behavior for `cache` command command: cache default-subcommand: info * breaking(cli): remove default behavior for `index` command command: index default-subcommand: list * breaking(cli): remove default behavior for `maintenance` command command: maintenance default-subcommand: run * breaking(cli): remove default behavior for `manifest` command command: manifest default-subcommand: list * breaking(cli): remove default behavior for `repository upgrade` command command: repository upgrade default-subcommand: begin * breaking(cli): remove default behavior for `server` command command: server default-subcommand: start
71 lines
1.8 KiB
Go
71 lines
1.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"sort"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
type commandIndexList struct {
|
|
blockIndexListSummary bool
|
|
blockIndexListIncludeSuperseded bool
|
|
blockIndexListSort string
|
|
|
|
jo jsonOutput
|
|
out textOutput
|
|
}
|
|
|
|
func (c *commandIndexList) setup(svc appServices, parent commandParent) {
|
|
cmd := parent.Command("list", "List content indexes").Alias("ls")
|
|
cmd.Flag("summary", "Display index blob summary").BoolVar(&c.blockIndexListSummary)
|
|
cmd.Flag("superseded", "Include inactive index files superseded by compaction").BoolVar(&c.blockIndexListIncludeSuperseded)
|
|
cmd.Flag("sort", "Index blob sort order").Default("time").EnumVar(&c.blockIndexListSort, "time", "size", "name")
|
|
c.jo.setup(svc, cmd)
|
|
c.out.setup(svc)
|
|
cmd.Action(svc.directRepositoryReadAction(c.run))
|
|
}
|
|
|
|
func (c *commandIndexList) run(ctx context.Context, rep repo.DirectRepository) error {
|
|
var jl jsonList
|
|
|
|
jl.begin(&c.jo)
|
|
defer jl.end()
|
|
|
|
blks, err := rep.IndexBlobs(ctx, c.blockIndexListIncludeSuperseded)
|
|
if err != nil {
|
|
return errors.Wrap(err, "error listing index blobs")
|
|
}
|
|
|
|
switch c.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 {
|
|
if c.jo.jsonOutput {
|
|
jl.emit(b)
|
|
} else {
|
|
c.out.printStdout("%-60v %10v %v %v\n", b.BlobID, b.Length, formatTimestampPrecise(b.Timestamp), b.Superseded)
|
|
}
|
|
}
|
|
|
|
if c.blockIndexListSummary && !c.jo.jsonOutput {
|
|
c.out.printStdout("total %v indexes\n", len(blks))
|
|
}
|
|
|
|
return nil
|
|
}
|