Skip to content

Commit

Permalink
fix(survey): avoid infinite loop if first variable is skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
majori committed Feb 5, 2024
1 parent 76f32a2 commit aeadec7
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/ui/survey/survey.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,21 +144,23 @@ func (m SurveyModel) Values() recipe.VariableValues {
}

func (m *SurveyModel) createNextPrompt() (prompt.Model, error) {
if len(m.prompts) > 0 {
m.cursor++
}

if m.cursor >= len(m.variables) {
return nil, nil
}

if p, err := m.createPrompt(m.variables[m.cursor]); err != nil {
p, err := m.createPrompt(m.variables[m.cursor])
if err != nil {
return nil, err
} else if p == nil {
}

m.cursor++

// Skip the prompt if it should be skipped (e.g. because of 'if' condition)
if p == nil {
return m.createNextPrompt()
} else {
return p, nil
}

return p, nil
}

// createPrompt creates a prompt for the given variable. Returns nil if the variable should be skipped.
Expand Down

0 comments on commit aeadec7

Please sign in to comment.