MCPcopy
hub / github.com/cli/cli / buildSelectForm

Method buildSelectForm

internal/prompter/huh_prompter.go:41–65  ·  view source on GitHub ↗
(prompt, defaultValue string, options []string)

Source from the content-addressed store, hash-verified

39}
40
41func (p *huhPrompter) buildSelectForm(prompt, defaultValue string, options []string) (*huh.Form, *int) {
42 var result int
43
44 if !slices.Contains(options, defaultValue) {
45 defaultValue = ""
46 }
47
48 formOptions := make([]huh.Option[int], len(options))
49 for i, o := range options {
50 if defaultValue == o {
51 result = i
52 }
53 formOptions[i] = huh.NewOption(o, i)
54 }
55
56 form := p.newForm(
57 huh.NewGroup(
58 huh.NewSelect[int]().
59 Title(prompt).
60 Value(&result).
61 Options(formOptions...),
62 ),
63 )
64 return form, &result
65}
66
67func (p *huhPrompter) Select(prompt, defaultValue string, options []string) (int, error) {
68 form, result := p.buildSelectForm(prompt, defaultValue, options)

Callers 3

SelectMethod · 0.95
TestHuhPrompterSelectFunction · 0.80

Calls 5

newFormMethod · 0.95
ContainsMethod · 0.80
OptionsMethod · 0.80
ValueMethod · 0.80
TitleMethod · 0.65

Tested by 2

TestHuhPrompterSelectFunction · 0.64