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

Function runMultiSelectWithSearch

pkg/cmd/preview/prompter/prompter.go:157–201  ·  view source on GitHub ↗
(p prompter.Prompter, io *iostreams.IOStreams)

Source from the content-addressed store, hash-verified

155}
156
157func runMultiSelectWithSearch(p prompter.Prompter, io *iostreams.IOStreams) error {
158 fmt.Fprintln(io.Out, "Demonstrating Multi Select With Search")
159 persistentOptions := []string{"persistent-option-1"}
160 searchFunc := func(input string) prompter.MultiSelectSearchResult {
161 var searchResultKeys []string
162 var searchResultLabels []string
163
164 if input == "" {
165 moreResults := 2 // Indicate that there are more results available
166 searchResultKeys = []string{"initial-result-1", "initial-result-2"}
167 searchResultLabels = []string{"Initial Result Label 1", "Initial Result Label 2"}
168 return prompter.MultiSelectSearchResult{
169 Keys: searchResultKeys,
170 Labels: searchResultLabels,
171 MoreResults: moreResults,
172 Err: nil,
173 }
174 }
175
176 // In a real implementation, this function would perform a search based on the input.
177 // Here, we return a static set of options for demonstration purposes.
178 moreResults := 0
179 searchResultKeys = []string{"search-result-1", "search-result-2"}
180 searchResultLabels = []string{"Search Result Label 1", "Search Result Label 2"}
181 return prompter.MultiSelectSearchResult{
182 Keys: searchResultKeys,
183 Labels: searchResultLabels,
184 MoreResults: moreResults,
185 Err: nil,
186 }
187 }
188
189 selections, err := p.MultiSelectWithSearch("Select an option", "Search for an option", []string{}, persistentOptions, searchFunc)
190 if err != nil {
191 return err
192 }
193
194 if len(selections) == 0 {
195 fmt.Fprintln(io.Out, "No options selected.")
196 return nil
197 }
198
199 fmt.Fprintf(io.Out, "Selected options: %s\n", strings.Join(selections, ", "))
200 return nil
201}
202
203func runInput(p prompter.Prompter, io *iostreams.IOStreams) error {
204 fmt.Fprintln(io.Out, "Demonstrating Text Input")

Callers

nothing calls this directly

Calls 2

JoinMethod · 0.80
MultiSelectWithSearchMethod · 0.65

Tested by

no test coverage detected