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

Function EnableRepoOverride

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

Source from the content-addressed store, hash-verified

34}
35
36func EnableRepoOverride(cmd *cobra.Command, f *Factory) {
37 cmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
38 _ = cmd.RegisterFlagCompletionFunc("repo", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
39 remotes, err := f.Remotes()
40 if err != nil {
41 return nil, cobra.ShellCompDirectiveError
42 }
43
44 config, err := f.Config()
45 if err != nil {
46 return nil, cobra.ShellCompDirectiveError
47 }
48 defaultHost, _ := config.Authentication().DefaultHost()
49
50 var results []string
51 for _, remote := range remotes {
52 repo := remote.RepoOwner() + "/" + remote.RepoName()
53 if !strings.EqualFold(remote.RepoHost(), defaultHost) {
54 repo = remote.RepoHost() + "/" + repo
55 }
56 if strings.HasPrefix(repo, toComplete) {
57 results = append(results, repo)
58 }
59 }
60 sort.Strings(results)
61 return results, cobra.ShellCompDirectiveNoFileComp
62 })
63
64 overrideCmd := cmd
65 cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
66 if err := executeParentHook(overrideCmd, cmd, args); err != nil {
67 return err
68 }
69 repoOverride, _ := cmd.Flags().GetString("repo")
70 f.BaseRepo = OverrideBaseRepoFunc(f.BaseRepo, repoOverride)
71 return nil
72 }
73}
74
75func OverrideBaseRepoFunc(baseRepoFunc func() (ghrepo.Interface, error), override string) func() (ghrepo.Interface, error) {
76 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

executeParentHookFunction · 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 6

TestNewCmdTransferFunction · 0.74
TestArgParsingFunction · 0.74