Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prompt opts to SelectConfig.Run #208

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions component/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,29 @@ type SelectConfig struct {
}

// Run the selection.
func (p *SelectConfig) Run(response interface{}) error {
return Select(p, response)
func (p *SelectConfig) Run(response interface{}, opts ...PromptOpt) error {
return Select(p, response, opts...)
}

// Select an option.
func Select(p *SelectConfig, response interface{}) error {
func Select(p *SelectConfig, response interface{}, opts ...PromptOpt) error {
if response == nil {
return errors.New("no response reference provided to record answers")
}
needMultipleSelect := isPointerToSlice(response)

prompt := buildSelect(p, needMultipleSelect)
return survey.AskOne(prompt, response)
options := defaultPromptOptions()
for _, opt := range opts {
err := opt(options)
if err != nil {
return err
}
}

surveyOpts := translatePromptOpts(options)

return survey.AskOne(prompt, response, surveyOpts...)
}

func buildSelect(p *SelectConfig, enableMultiSelect bool) survey.Prompt {
Expand Down
Loading