MCPcopy
hub / github.com/go-task/task / Select

Method Select

internal/input/input.go:54–77  ·  view source on GitHub ↗

Select prompts the user to select from a list of options

(varName string, options []string)

Source from the content-addressed store, hash-verified

52
53// Select prompts the user to select from a list of options
54func (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
80func (p *Prompter) Prompt(varName string, enum []string) (string, error) {

Callers 1

PromptMethod · 0.95

Calls 3

NewFunction · 0.92
newSelectModelFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected