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

Function SelectMap

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

Source from the content-addressed store, hash-verified

46}
47
48func SelectMap[T any](ask Asker, message string, items []T, getKey func(item T) string) (T, error) {
49 if util.Empty(items) {
50 return *new(T), fmt.Errorf("%s - no options available", message)
51 }
52 optionMap, options := MakeItemMapAndOptions(items, getKey)
53 var selectedValue T
54 var selectedKey string
55 if err := ask(&survey.Select{
56 Message: message,
57 Options: options,
58 }, &selectedKey); err != nil {
59 return selectedValue, err
60 }
61 selectedValue, ok := optionMap[selectedKey]
62 if !ok { // without this explict check SelectMap can return nil, nil which people don't expect
63 return *new(T), fmt.Errorf("SelectMap did not get valid answer (selectedKey=%s)", selectedKey)
64 }
65 return selectedValue, nil
66}
67
68func SelectMapWithNew[T any](ask Asker, message string, items []T, getKey func(item T) string) (T, bool, error) {
69 optionMap, options := MakeItemMapAndOptions(items, getKey)

Callers 15

GetSpacedClientMethod · 0.92
AskPackageDownloadFunction · 0.92
AskGuidedFailureModeFunction · 0.92
selectReleaseFunction · 0.92
determineIsTenantedFunction · 0.92
SelectReleaseFunction · 0.92
selectGitReferenceFunction · 0.92
selectPackageFunction · 0.92
selectVersionFunction · 0.92
projectSelectorFunction · 0.92
projectSelectorFunction · 0.92
projectSelectorFunction · 0.92

Calls 2

EmptyFunction · 0.92
MakeItemMapAndOptionsFunction · 0.85

Tested by 1

TestSelectMap_NoItemsFunction · 0.74