From e4d748207d70d2632756859a24018b2fcc5357c4 Mon Sep 17 00:00:00 2001 From: William Bezuidenhout Date: Wed, 6 May 2026 10:38:57 +0200 Subject: [PATCH] dedupe migrated root commands --- cmd/src/run_migration_compat.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/cmd/src/run_migration_compat.go b/cmd/src/run_migration_compat.go index 52baca0fc5..2d61167155 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" @@ -43,16 +45,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",