1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-01-03 13:45:20 +00:00

Issue 4433:

cmd_find: ability to define sort order for output of find command:
Add option --reverse
This commit is contained in:
Winfried Plappert 2024-12-16 15:15:26 +00:00
parent 6808004ad1
commit 12de59a55f
2 changed files with 11 additions and 0 deletions

View file

@ -0,0 +1,5 @@
Enhancement: allow to define sorting order of command restic find.
Add option --reverse
https://github.com/restic/restic/issues/4433

View file

@ -3,6 +3,7 @@ package main
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"slices"
"sort" "sort"
"strings" "strings"
"time" "time"
@ -56,6 +57,7 @@ type FindOptions struct {
CaseInsensitive bool CaseInsensitive bool
ListLong bool ListLong bool
HumanReadable bool HumanReadable bool
Reverse bool
restic.SnapshotFilter restic.SnapshotFilter
} }
@ -73,6 +75,7 @@ func init() {
f.BoolVar(&findOptions.PackID, "pack", false, "pattern is a pack-ID") f.BoolVar(&findOptions.PackID, "pack", false, "pattern is a pack-ID")
f.BoolVar(&findOptions.ShowPackID, "show-pack-id", false, "display the pack-ID the blobs belong to (with --blob or --tree)") f.BoolVar(&findOptions.ShowPackID, "show-pack-id", false, "display the pack-ID the blobs belong to (with --blob or --tree)")
f.BoolVarP(&findOptions.CaseInsensitive, "ignore-case", "i", false, "ignore case for pattern") f.BoolVarP(&findOptions.CaseInsensitive, "ignore-case", "i", false, "ignore case for pattern")
f.BoolVarP(&findOptions.Reverse, "reverse", "R", false, "reverse sort order newest->oldest")
f.BoolVarP(&findOptions.ListLong, "long", "l", false, "use a long listing format showing size and mode") f.BoolVarP(&findOptions.ListLong, "long", "l", false, "use a long listing format showing size and mode")
f.BoolVar(&findOptions.HumanReadable, "human-readable", false, "print sizes in human readable format") f.BoolVar(&findOptions.HumanReadable, "human-readable", false, "print sizes in human readable format")
@ -628,6 +631,9 @@ func runFind(ctx context.Context, opts FindOptions, gopts GlobalOptions, args []
sort.Slice(filteredSnapshots, func(i, j int) bool { sort.Slice(filteredSnapshots, func(i, j int) bool {
return filteredSnapshots[i].Time.Before(filteredSnapshots[j].Time) return filteredSnapshots[i].Time.Before(filteredSnapshots[j].Time)
}) })
if opts.Reverse {
slices.Reverse(filteredSnapshots)
}
for _, sn := range filteredSnapshots { for _, sn := range filteredSnapshots {
if f.blobIDs != nil || f.treeIDs != nil { if f.blobIDs != nil || f.treeIDs != nil {