| 40 | } |
| 41 | |
| 42 | func Select[T any](ask question.Asker, questionText string, itemsCallback func() ([]T, error), getKey func(item T) string) (T, error) { |
| 43 | items, err := itemsCallback() |
| 44 | if err != nil { |
| 45 | var item T |
| 46 | return item, err |
| 47 | } |
| 48 | if len(items) == 1 { |
| 49 | return items[0], nil |
| 50 | } |
| 51 | |
| 52 | return question.SelectMap(ask, questionText, items, getKey) |
| 53 | } |
| 54 | |
| 55 | // SelectOrNew is the same as Select but show a create new option at the bottom of the list |
| 56 | // When create new is selected the returned bool will be true |