Select prompts the user to select from a list of options
(varName string, options []string)
| 52 | |
| 53 | // Select prompts the user to select from a list of options |
| 54 | func (p *Prompter) Select(varName string, options []string) (string, error) { |
| 55 | if len(options) == 0 { |
| 56 | return "", errors.New("no options provided") |
| 57 | } |
| 58 | |
| 59 | m := newSelectModel(varName, options) |
| 60 | |
| 61 | prog := tea.NewProgram(m, |
| 62 | tea.WithInput(p.Stdin), |
| 63 | tea.WithOutput(p.Stderr), |
| 64 | ) |
| 65 | |
| 66 | result, err := prog.Run() |
| 67 | if err != nil { |
| 68 | return "", err |
| 69 | } |
| 70 | |
| 71 | model := result.(selectModel) |
| 72 | if model.cancelled { |
| 73 | return "", ErrCancelled |
| 74 | } |
| 75 | |
| 76 | return model.options[model.cursor], nil |
| 77 | } |
| 78 | |
| 79 | // Prompt prompts for a variable value, using Select if enum is provided, Text otherwise |
| 80 | func (p *Prompter) Prompt(varName string, enum []string) (string, error) { |
no test coverage detected