diff --git a/cmd/src/run_migration_compat.go b/cmd/src/run_migration_compat.go index d4f8b55011..6d3bdb7778 100644 --- a/cmd/src/run_migration_compat.go +++ b/cmd/src/run_migration_compat.go @@ -1,12 +1,14 @@ package main import ( + "cmp" "context" "flag" "fmt" "log" + "maps" "os" - "sort" + "slices" "github.com/sourcegraph/src-cli/internal/clicompat" "github.com/sourcegraph/src-cli/internal/cmderrors" @@ -46,16 +48,13 @@ func maybeRunMigratedCommand() (isMigrated bool, exitCode int, err error) { // migratedRootCommand constructs a root 'src' command and adds // MigratedCommands as subcommands to it func migratedRootCommand() *cli.Command { - names := make([]string, 0, len(migratedCommands)) - for name := range migratedCommands { - names = append(names, name) - } - sort.Strings(names) - - commands := make([]*cli.Command, 0, len(names)) - for _, name := range names { - commands = append(commands, migratedCommands[name]) + uniqueCommands := make(map[string]*cli.Command, len(migratedCommands)) + for _, cmd := range migratedCommands { + uniqueCommands[cmd.Name] = cmd } + commands := slices.SortedFunc(maps.Values(uniqueCommands), func(a, b *cli.Command) int { + return cmp.Compare(a.Name, b.Name) + }) return clicompat.Wrap(&cli.Command{ Name: "src",