MCPcopy Create free account
hub / github.com/OctopusDeploy/cli / MultiSelectMap

Function MultiSelectMap

pkg/question/select.go:12–33  ·  view source on GitHub ↗
(ask Asker, message string, items []T, getKey func(item T) string, required bool)

Source from the content-addressed store, hash-verified

10)
11
12func MultiSelectMap[T any](ask Asker, message string, items []T, getKey func(item T) string, required bool) ([]T, error) {
13 if util.Empty(items) {
14 return nil, fmt.Errorf("%s - no options available", message)
15 }
16 optionMap, options := MakeItemMapAndOptions(items, getKey)
17
18 askOpts := func(options *survey.AskOptions) error { return nil }
19 if required {
20 askOpts = survey.WithValidator(survey.Required)
21 }
22
23 var selectedKeys []string
24 if err := ask(&survey.MultiSelect{Message: message, Options: options}, &selectedKeys, askOpts); err != nil {
25 return nil, err
26 }
27 selected := make([]T, 0)
28 for _, keyName := range selectedKeys {
29 selected = append(selected, optionMap[keyName])
30 }
31 // it's valid to have zero selected options in a multi-select
32 return selected, nil
33}
34
35func MultiSelectWithAddMap(ask Asker, message string, items []string, required bool) ([]string, error) {
36 askOpts := func(options *survey.AskOptions) error { return nil }

Callers 14

AskExcludedStepsFunction · 0.92
selectReleasesFunction · 0.92
PromptMissingFunction · 0.92
PromptMissingFunction · 0.92
selectRunEnvironmentsFunction · 0.92
selectGitRunEnvironmentsFunction · 0.92
PromptForWorkerPoolsFunction · 0.92
PromptMissingFunction · 0.92
selectTeamsFunction · 0.92
selectUsersFunction · 0.92
promptSubjectKeysFunction · 0.92
promptSubjectKeysFunction · 0.92

Calls 2

EmptyFunction · 0.92
MakeItemMapAndOptionsFunction · 0.85

Tested by 1