MCPcopy
hub / github.com/cli/cli / PromptWhenAmbiguousBaseRepoFunc

Function PromptWhenAmbiguousBaseRepoFunc

pkg/cmd/secret/shared/base_repo.go:24–54  ·  view source on GitHub ↗
(baseRepoFn baseRepoFn, ios *iostreams.IOStreams, prompter prompter.Prompter)

Source from the content-addressed store, hash-verified

22type remotesFn func() (ghContext.Remotes, error)
23
24func PromptWhenAmbiguousBaseRepoFunc(baseRepoFn baseRepoFn, ios *iostreams.IOStreams, prompter prompter.Prompter) baseRepoFn {
25 return func() (ghrepo.Interface, error) {
26 baseRepo, err := baseRepoFn()
27 if err != nil {
28 var ambiguousBaseRepoErr AmbiguousBaseRepoError
29 if !errors.As(err, &ambiguousBaseRepoErr) {
30 return nil, err
31 }
32
33 baseRepoOptions := make([]string, len(ambiguousBaseRepoErr.Remotes))
34 for i, remote := range ambiguousBaseRepoErr.Remotes {
35 baseRepoOptions[i] = ghrepo.FullName(remote)
36 }
37
38 fmt.Fprintf(ios.Out, "%s Multiple remotes detected. Due to the sensitive nature of secrets, requiring disambiguation.\n", ios.ColorScheme().WarningIcon())
39 selectedBaseRepo, err := prompter.Select("Select a repo", baseRepoOptions[0], baseRepoOptions)
40 if err != nil {
41 return nil, err
42 }
43
44 selectedRepo, err := ghrepo.FromFullName(baseRepoOptions[selectedBaseRepo])
45 if err != nil {
46 return nil, err
47 }
48
49 return selectedRepo, nil
50 }
51
52 return baseRepo, nil
53 }
54}
55
56// RequireNoAmbiguityBaseRepoFunc returns a function to resolve the base repo, ensuring that
57// there was only one option, regardless of whether the base repo had been set.

Callers 4

NewCmdDeleteFunction · 0.92
NewCmdListFunction · 0.92
NewCmdSetFunction · 0.92

Calls 6

FullNameFunction · 0.92
FromFullNameFunction · 0.92
baseRepoFnFuncType · 0.85
WarningIconMethod · 0.80
ColorSchemeMethod · 0.80
SelectMethod · 0.65