feat(commands): sort /help output alphabetically

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
seagochen 2026-03-09 15:28:54 +08:00
parent ed1d5ec4ea
commit a2bb4c7704

View file

@ -3,6 +3,7 @@ package commands
import (
"context"
"fmt"
"sort"
"strings"
)
@ -28,8 +29,12 @@ func formatHelpMessage(defs []Definition) string {
return "No commands available."
}
lines := make([]string, 0, len(defs))
for _, def := range defs {
sorted := make([]Definition, len(defs))
copy(sorted, defs)
sort.Slice(sorted, func(i, j int) bool { return sorted[i].Name < sorted[j].Name })
lines := make([]string, 0, len(sorted))
for _, def := range sorted {
usage := def.EffectiveUsage()
if usage == "" {
usage = "/" + def.Name