MCPcopy
hub / github.com/cli/cli / checkValidExtension

Function checkValidExtension

pkg/cmd/extension/command.go:694–714  ·  view source on GitHub ↗
(rootCmd *cobra.Command, m extensions.ExtensionManager, extName, extOwner string)

Source from the content-addressed store, hash-verified

692}
693
694func 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
716func normalizeExtensionSelector(n string) string {
717 if idx := strings.IndexRune(n, '/'); idx >= 0 {

Callers 3

Test_checkValidExtensionFunction · 0.85
NewCmdExtensionFunction · 0.85

Calls 5

FindMethod · 0.65
ErrorfMethod · 0.65
ListMethod · 0.65
NameMethod · 0.65
OwnerMethod · 0.65