refactor(cmd): migrate sort.Slice to slices.SortFunc (bd-u2sc.2)
Modernize sorting code to use Go 1.21+ slices package: - Replace sort.Slice with slices.SortFunc across 16 files - Use cmp.Compare for orderable types (strings, ints) - Use time.Time.Compare for time comparisons - Use cmp.Or for multi-field sorting - Use slices.SortStableFunc where stability matters Benefits: cleaner 3-way comparison, slightly better performance, modern idiomatic Go. Part of GH#692 refactoring epic. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"cmp"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -205,8 +206,11 @@ Examples:
|
||||
outputJSON(result)
|
||||
} else {
|
||||
// Sort groups for consistent output
|
||||
sort.Slice(result.Groups, func(i, j int) bool {
|
||||
return result.Groups[i].Group < result.Groups[j].Group
|
||||
slices.SortFunc(result.Groups, func(a, b struct {
|
||||
Group string `json:"group"`
|
||||
Count int `json:"count"`
|
||||
}) int {
|
||||
return cmp.Compare(a.Group, b.Group)
|
||||
})
|
||||
|
||||
fmt.Printf("Total: %d\n\n", result.Total)
|
||||
@@ -397,8 +401,8 @@ Examples:
|
||||
}
|
||||
|
||||
// Sort for consistent output
|
||||
sort.Slice(groups, func(i, j int) bool {
|
||||
return groups[i].Group < groups[j].Group
|
||||
slices.SortFunc(groups, func(a, b GroupCount) int {
|
||||
return cmp.Compare(a.Group, b.Group)
|
||||
})
|
||||
|
||||
if jsonOutput {
|
||||
|
||||
Reference in New Issue
Block a user