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

Method MultiSelect

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

Source from the content-addressed store, hash-verified

146}
147
148func (p *accessiblePrompter) MultiSelect(prompt string, defaults []string, options []string) ([]int, error) {
149 var result []int
150
151 // Remove invalid default values from the defaults slice.
152 defaults = slices.DeleteFunc(defaults, func(s string) bool {
153 return !slices.Contains(options, s)
154 })
155
156 prompt = p.addDefaultsToPrompt(prompt, defaults)
157 formOptions := make([]huh.Option[int], len(options))
158 for i, o := range options {
159 // If this option is in the defaults slice,
160 // let's add its index to the result slice and huh
161 // will treat it as a default selection.
162 if slices.Contains(defaults, o) {
163 result = append(result, i)
164 }
165
166 formOptions[i] = huh.NewOption(o, i)
167 }
168
169 form := p.newForm(
170 huh.NewGroup(
171 huh.NewMultiSelect[int]().
172 Title(prompt).
173 Value(&result).
174 Limit(len(options)).
175 Options(formOptions...),
176 ),
177 )
178
179 if err := form.Run(); err != nil {
180 return nil, err
181 }
182
183 return result, nil
184}
185
186func (p *accessiblePrompter) Input(prompt, defaultValue string) (string, error) {
187 result := defaultValue

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected