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