MCPcopy
hub / github.com/cli/cli / EnableRepoOverride

Function EnableRepoOverride

pkg/cmdutil/repo_override.go:22–58  ·  view source on GitHub ↗
(cmd *cobra.Command, f *Factory)

Source from the content-addressed store, hash-verified

20}
21
22func EnableRepoOverride(cmd *cobra.Command, f *Factory) {
23 cmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
24 _ = cmd.RegisterFlagCompletionFunc("repo", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
25 remotes, err := f.Remotes()
26 if err != nil {
27 return nil, cobra.ShellCompDirectiveError
28 }
29
30 config, err := f.Config()
31 if err != nil {
32 return nil, cobra.ShellCompDirectiveError
33 }
34 defaultHost, _ := config.Authentication().DefaultHost()
35
36 var results []string
37 for _, remote := range remotes {
38 repo := remote.RepoOwner() + "/" + remote.RepoName()
39 if !strings.EqualFold(remote.RepoHost(), defaultHost) {
40 repo = remote.RepoHost() + "/" + repo
41 }
42 if strings.HasPrefix(repo, toComplete) {
43 results = append(results, repo)
44 }
45 }
46 sort.Strings(results)
47 return results, cobra.ShellCompDirectiveNoFileComp
48 })
49
50 cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
51 if err := executeParentHooks(cmd, args); err != nil {
52 return err
53 }
54 repoOverride, _ := cmd.Flags().GetString("repo")
55 f.BaseRepo = OverrideBaseRepoFunc(f.BaseRepo, repoOverride)
56 return nil
57 }
58}
59
60func OverrideBaseRepoFunc(baseRepoFunc func() (ghrepo.Interface, error), override string) func() (ghrepo.Interface, error) {
61 if override == "" {

Callers 15

NewCmdCacheFunction · 0.92
NewCmdDiscussionFunction · 0.92
NewCmdViewFunction · 0.92
NewCmdListFunction · 0.92
NewCmdCommentFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdEditFunction · 0.92
NewCmdRulesetFunction · 0.92
NewCmdReleaseFunction · 0.92
NewCmdViewFunction · 0.92
NewCmdCreateFunction · 0.92
NewCmdLinkFunction · 0.92

Calls 9

executeParentHooksFunction · 0.85
OverrideBaseRepoFuncFunction · 0.85
RemotesMethod · 0.65
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65

Tested by 5

TestNewCmdTransferFunction · 0.74
TestArgParsingFunction · 0.74