| 691 | } |
| 692 | |
| 693 | func checkValidExtension(rootCmd *cobra.Command, m extensions.ExtensionManager, extName, extOwner string) (extensions.Extension, error) { |
| 694 | if !strings.HasPrefix(extName, "gh-") { |
| 695 | return nil, errors.New("extension name must start with `gh-`") |
| 696 | } |
| 697 | |
| 698 | commandName := strings.TrimPrefix(extName, "gh-") |
| 699 | if c, _, _ := rootCmd.Find([]string{commandName}); c != rootCmd && c.GroupID != "extension" { |
| 700 | return nil, fmt.Errorf("%q matches the name of a built-in command or alias", commandName) |
| 701 | } |
| 702 | |
| 703 | for _, ext := range m.List() { |
| 704 | if ext.Name() == commandName { |
| 705 | if extOwner != "" && ext.Owner() == extOwner { |
| 706 | return ext, alreadyInstalledError |
| 707 | } |
| 708 | return ext, fmt.Errorf("there is already an installed extension that provides the %q command", commandName) |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | return nil, nil |
| 713 | } |
| 714 | |
| 715 | func normalizeExtensionSelector(n string) string { |
| 716 | if idx := strings.IndexRune(n, '/'); idx >= 0 { |