Skip to content

Commit 07c8f47

Browse files
committed
cmd/docker-trust: update naturalsort sorting with slices
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent d4f29e6 commit 07c8f47

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

‎cmd/docker-trust/trust/common.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"encoding/hex"
66
"fmt"
77
"slices"
8-
"sort"
98
"strings"
109

1110
"github.com/docker/cli/cli/command"
@@ -163,8 +162,8 @@ func matchReleasedSignatures(allTargets []client.TargetSignedStruct) []trustTagR
163162
for targetKey, signers := range releasedTargetRows {
164163
signatureRows = append(signatureRows, trustTagRow{targetKey, signers})
165164
}
166-
sort.Slice(signatureRows, func(i, j int) bool {
167-
return sortorder.NaturalLess(signatureRows[i].SignedTag, signatureRows[j].SignedTag)
165+
slices.SortFunc(signatureRows, func(a, b trustTagRow) int {
166+
return sortorder.NaturalCompare(a.SignedTag, b.SignedTag)
168167
})
169168
return signatureRows
170169
}

‎cmd/docker-trust/trust/inspect_pretty.go‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"fmt"
77
"io"
88
"slices"
9-
"sort"
109

1110
"github.com/docker/cli/cli/command"
1211
"github.com/docker/cli/cli/command/formatter"
@@ -85,15 +84,15 @@ func printSignerInfo(out io.Writer, roleToKeyIDs map[string][]string) error {
8584
Format: defaultSignerInfoTableFormat,
8685
Trunc: true,
8786
}
88-
formattedSignerInfo := []signerInfo{}
87+
formattedSignerInfo := make([]signerInfo, 0, len(roleToKeyIDs))
8988
for name, keyIDs := range roleToKeyIDs {
9089
formattedSignerInfo = append(formattedSignerInfo, signerInfo{
9190
Name: name,
9291
Keys: keyIDs,
9392
})
9493
}
95-
sort.Slice(formattedSignerInfo, func(i, j int) bool {
96-
return sortorder.NaturalLess(formattedSignerInfo[i].Name, formattedSignerInfo[j].Name)
94+
slices.SortFunc(formattedSignerInfo, func(a, b signerInfo) int {
95+
return sortorder.NaturalCompare(a.Name, b.Name)
9796
})
9897
return signerInfoWrite(signerInfoCtx, formattedSignerInfo)
9998
}

0 commit comments

Comments
 (0)