Merge pull request #7269 from thaJeztah/slice_and_dice_step2

update naturalsort sorting with slice
This commit is contained in:
Sebastiaan van Stijn
2026-09-03 15:28:39 +02:00
committed by GitHub
18 changed files with 98 additions and 74 deletions
+2 -3
View File
@@ -5,7 +5,6 @@ import (
"encoding/hex"
"fmt"
"slices"
"sort"
"strings"
"github.com/docker/cli/cli/command"
@@ -163,8 +162,8 @@ func matchReleasedSignatures(allTargets []client.TargetSignedStruct) []trustTagR
for targetKey, signers := range releasedTargetRows {
signatureRows = append(signatureRows, trustTagRow{targetKey, signers})
}
sort.Slice(signatureRows, func(i, j int) bool {
return sortorder.NaturalLess(signatureRows[i].SignedTag, signatureRows[j].SignedTag)
slices.SortFunc(signatureRows, func(a, b trustTagRow) int {
return sortorder.NaturalCompare(a.SignedTag, b.SignedTag)
})
return signatureRows
}
+3 -4
View File
@@ -6,7 +6,6 @@ import (
"fmt"
"io"
"slices"
"sort"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
@@ -85,15 +84,15 @@ func printSignerInfo(out io.Writer, roleToKeyIDs map[string][]string) error {
Format: defaultSignerInfoTableFormat,
Trunc: true,
}
formattedSignerInfo := []signerInfo{}
formattedSignerInfo := make([]signerInfo, 0, len(roleToKeyIDs))
for name, keyIDs := range roleToKeyIDs {
formattedSignerInfo = append(formattedSignerInfo, signerInfo{
Name: name,
Keys: keyIDs,
})
}
sort.Slice(formattedSignerInfo, func(i, j int) bool {
return sortorder.NaturalLess(formattedSignerInfo[i].Name, formattedSignerInfo[j].Name)
slices.SortFunc(formattedSignerInfo, func(a, b signerInfo) int {
return sortorder.NaturalCompare(a.Name, b.Name)
})
return signerInfoWrite(signerInfoCtx, formattedSignerInfo)
}