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

Method Choose

pkg/cmd/pr/shared/templates.go:183–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

181}
182
183func (m *templateManager) Choose() (Template, error) {
184 if err := m.memoizedFetch(); err != nil {
185 return nil, err
186 }
187 if len(m.templates) == 0 {
188 return nil, nil
189 }
190
191 names := make([]string, len(m.templates))
192 for i, t := range m.templates {
193 names[i] = t.Name()
194 }
195
196 blankOption := "Open a blank issue"
197 if m.isPR {
198 blankOption = "Open a blank pull request"
199 }
200
201 selectedOption, err := m.prompter.Select("Choose a template", "", append(names, blankOption))
202 if err != nil {
203 return nil, fmt.Errorf("could not prompt: %w", err)
204 }
205
206 if selectedOption == len(names) {
207 return nil, nil
208 }
209 return m.templates[selectedOption], nil
210}
211
212func (m *templateManager) Select(name string) (Template, error) {
213 if err := m.memoizedFetch(); err != nil {

Callers 4

createRunFunction · 0.80
createRunFunction · 0.80

Calls 4

memoizedFetchMethod · 0.95
NameMethod · 0.65
SelectMethod · 0.65
ErrorfMethod · 0.65

Tested by 2