Skip to content

Commit

Permalink
Ensure that step has a unique id in the dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMatejka committed Mar 31, 2022
1 parent 1b6c855 commit 1789eb4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions internal/pkg/cli/dialog/steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (d *stepsDialog) parse(result string) (input.StepsGroups, map[input.StepInd
var currentGroup *input.StepsGroup
var currentStep *input.Step
stepsToIds := make(map[input.StepIndex]string)
usedIds := make(map[string]bool)

var invalidDefinition bool

Expand Down Expand Up @@ -89,6 +90,11 @@ func (d *stepsDialog) parse(result string) (input.StepsGroups, map[input.StepInd
Step: len(currentGroup.Steps) - 1,
Group: len(stepsGroups) - 1,
}
if usedIds[m[1]] {
errors.Append(fmt.Errorf(`line %d: step with id "%s" is already defined`, lineNum, m[1]))
continue
}
usedIds[m[1]] = true
stepsToIds[index] = m[1]

invalidDefinition = false
Expand Down
8 changes: 7 additions & 1 deletion internal/pkg/cli/dialog/steps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ description:
## Group
description:
### Step "s1"
name: Step One again
description: Description
icon: common
### Step "s2"
name: Step Two
description: Description
Expand All @@ -99,14 +104,15 @@ description: Description
expected := `
- line 2: there needs to be a group definition before step "s0"
- line 12: required is not valid option for a step
- line 21: step with id "s1" is already defined
- group 1: required must be one of [all atLeastOne exactOne zeroOrOne optional]
- group 1, step 1: icon is a required field
- group 1, step 1: name must be a maximum of 20 characters in length
- group 2: required must be one of [all atLeastOne exactOne zeroOrOne optional]
- group 2: steps must contain at least 1 step
- group 3: required must be one of [all atLeastOne exactOne zeroOrOne optional]
- group 3, step 1: icon is a required field
- group 3, step 2: icon is a required field
- group 3, step 3: icon is a required field
`

// Parse
Expand Down

0 comments on commit 1789eb4

Please sign in to comment.