Skip to content

Commit

Permalink
Add prompt opts to SelectConfig.Run (#208)
Browse files Browse the repository at this point in the history
Co-authored-by: Gabriel Saliev <[email protected]>
  • Loading branch information
gabbigum and Gabriel Saliev authored Aug 27, 2024
1 parent de610f9 commit e7a4e03
Showing 1 changed file with 14 additions and 4 deletions.
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

0 comments on commit e7a4e03

Please sign in to comment.