MCPcopy
hub / github.com/mislav/hub / transformRemoteArgs

Function transformRemoteArgs

commands/remote.go:57–141  ·  view source on GitHub ↗
(args *Args)

Source from the content-addressed store, hash-verified

55}
56
57func transformRemoteArgs(args *Args) {
58 ownerWithName := args.LastParam()
59
60 re := regexp.MustCompile(fmt.Sprintf(`^%s(/%s)?$`, OwnerRe, NameRe))
61 if !re.MatchString(ownerWithName) {
62 return
63 }
64 owner := ownerWithName
65 name := ""
66 if strings.Contains(ownerWithName, "/") {
67 parts := strings.SplitN(ownerWithName, "/", 2)
68 owner, name = parts[0], parts[1]
69 }
70
71 localRepo, err := github.LocalRepo()
72 utils.Check(err)
73
74 var host string
75 mainProject, err := localRepo.MainProject()
76 if err == nil {
77 host = mainProject.Host
78 }
79
80 if name == "" {
81 if mainProject != nil {
82 name = mainProject.Name
83 } else {
84 dirName, err := git.WorkdirName()
85 utils.Check(err)
86 name = github.SanitizeProjectName(dirName)
87 }
88 }
89
90 var hostConfig *github.Host
91 if host == "" {
92 hostConfig, err = github.CurrentConfig().DefaultHost()
93 } else {
94 hostConfig, err = github.CurrentConfig().PromptForHost(host)
95 }
96 if err != nil {
97 utils.Check(github.FormatError("adding remote", err))
98 }
99 host = hostConfig.Host
100
101 p := utils.NewArgsParser()
102 p.RegisterValue("-t")
103 p.RegisterValue("-m")
104 params, _ := p.Parse(args.Params)
105 if len(params) > 3 {
106 return
107 }
108
109 for i, pi := range p.PositionalIndices {
110 if i == 1 && strings.Contains(params[i], "/") {
111 args.ReplaceParam(pi, owner)
112 } else if i == 2 {
113 args.RemoveParam(pi)
114 }

Callers 2

TestTransformRemoteArgsFunction · 0.85
remoteFunction · 0.85

Calls 15

RegisterValueMethod · 0.95
ParseMethod · 0.95
RepositoryMethod · 0.95
GitURLMethod · 0.95
LocalRepoFunction · 0.92
CheckFunction · 0.92
WorkdirNameFunction · 0.92
SanitizeProjectNameFunction · 0.92
CurrentConfigFunction · 0.92
FormatErrorFunction · 0.92
NewArgsParserFunction · 0.92
NewProjectFunction · 0.92

Tested by 1

TestTransformRemoteArgsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…