MCPcopy Create free account
hub / github.com/cli/cli / checkValidExtension

Function checkValidExtension

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

Source from the content-addressed store, hash-verified

691}
692
693func 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
715func normalizeExtensionSelector(n string) string {
716 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