MCPcopy Index your code
hub / github.com/cli/cli / buildMultiSelectForm

Method buildMultiSelectForm

internal/prompter/huh_prompter.go:73–98  ·  view source on GitHub ↗
(prompt string, defaults []string, options []string)

Source from the content-addressed store, hash-verified

71}
72
73func (p *huhPrompter) buildMultiSelectForm(prompt string, defaults []string, options []string) (*huh.Form, *[]int) {
74 var result []int
75
76 defaults = slices.DeleteFunc(defaults, func(s string) bool {
77 return !slices.Contains(options, s)
78 })
79
80 formOptions := make([]huh.Option[int], len(options))
81 for i, o := range options {
82 if slices.Contains(defaults, o) {
83 result = append(result, i)
84 }
85 formOptions[i] = huh.NewOption(o, i)
86 }
87
88 form := p.newForm(
89 huh.NewGroup(
90 huh.NewMultiSelect[int]().
91 Title(prompt).
92 Value(&result).
93 Limit(len(options)).
94 Options(formOptions...),
95 ),
96 )
97 return form, &result
98}
99
100func (p *huhPrompter) MultiSelect(prompt string, defaults []string, options []string) ([]int, error) {
101 form, result := p.buildMultiSelectForm(prompt, defaults, options)

Callers 2

MultiSelectMethod · 0.95

Calls 5

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

Tested by 1