(msg string, options []string, def string)
| 9 | ) |
| 10 | |
| 11 | func SelectPrompt(msg string, options []string, def string) (string, error) { |
| 12 | prompt := &survey.Select{ |
| 13 | Message: msg, |
| 14 | Options: options, |
| 15 | } |
| 16 | |
| 17 | if slices.Contains(options, def) { |
| 18 | prompt.Default = def |
| 19 | } |
| 20 | |
| 21 | result := "" |
| 22 | if err := survey.AskOne(prompt, &result); err != nil { |
| 23 | return "", fmt.Errorf("prompt failed: %w", err) |
| 24 | } |
| 25 | return result, nil |
| 26 | } |
| 27 | |
| 28 | // SelectPromptWithDescriptions is like SelectPrompt but shows a description next to each option. |
| 29 | // The descriptions slice must be the same length as options. |
no test coverage detected