Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions cmd/src/run_migration_compat.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have commands with duplicated names? IE do we need to add a unique step?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah in the subsequent migration of codeowners and orgs we register the command twice in the set to support their current aliases.

}
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",
Expand Down
Loading