Skip to content

Commit e4d7482

Browse files
committed
dedupe migrated root commands
1 parent 82de268 commit e4d7482

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"
@@ -43,16 +45,13 @@ func maybeRunMigratedCommand() (isMigrated bool, exitCode int, err error) {
4345
// migratedRootCommand constructs a root 'src' command and adds
4446
// MigratedCommands as subcommands to it
4547
func migratedRootCommand() *cli.Command {
46-
names := make([]string, 0, len(migratedCommands))
47-
for name := range migratedCommands {
48-
names = append(names, name)
49-
}
50-
sort.Strings(names)
51-
52-
commands := make([]*cli.Command, 0, len(names))
53-
for _, name := range names {
54-
commands = append(commands, migratedCommands[name])
48+
uniqueCommands := make(map[string]*cli.Command, len(migratedCommands))
49+
for _, cmd := range migratedCommands {
50+
uniqueCommands[cmd.Name] = cmd
5551
}
52+
commands := slices.SortedFunc(maps.Values(uniqueCommands), func(a, b *cli.Command) int {
53+
return cmp.Compare(a.Name, b.Name)
54+
})
5655

5756
return clicompat.Wrap(&cli.Command{
5857
Name: "src",

0 commit comments

Comments
 (0)