Skip to content

Commit 618d038

Browse files
authored
dedupe migrated root commands (#1315)
1 parent fcb9939 commit 618d038

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

cmd/src/run_migration_compat.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
package main
22

33
import (
4+
"cmp"
45
"context"
56
"flag"
67
"fmt"
78
"log"
9+
"maps"
810
"os"
9-
"sort"
11+
"slices"
1012

1113
"github.com/sourcegraph/src-cli/internal/clicompat"
1214
"github.com/sourcegraph/src-cli/internal/cmderrors"
@@ -46,16 +48,13 @@ func maybeRunMigratedCommand() (isMigrated bool, exitCode int, err error) {
4648
// migratedRootCommand constructs a root 'src' command and adds
4749
// MigratedCommands as subcommands to it
4850
func migratedRootCommand() *cli.Command {
49-
names := make([]string, 0, len(migratedCommands))
50-
for name := range migratedCommands {
51-
names = append(names, name)
52-
}
53-
sort.Strings(names)
54-
55-
commands := make([]*cli.Command, 0, len(names))
56-
for _, name := range names {
57-
commands = append(commands, migratedCommands[name])
51+
uniqueCommands := make(map[string]*cli.Command, len(migratedCommands))
52+
for _, cmd := range migratedCommands {
53+
uniqueCommands[cmd.Name] = cmd
5854
}
55+
commands := slices.SortedFunc(maps.Values(uniqueCommands), func(a, b *cli.Command) int {
56+
return cmp.Compare(a.Name, b.Name)
57+
})
5958

6059
return clicompat.Wrap(&cli.Command{
6160
Name: "src",

0 commit comments

Comments
 (0)