Skip to content

Commit

Permalink
Merge pull request #87 from hashicorp/f-must-constraint
Browse files Browse the repository at this point in the history
Introduce `MustConstraints()`
  • Loading branch information
radeksimko authored Nov 22, 2021
2 parents c2de231 + 43df615 commit ac9bfc9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions constraint.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ func NewConstraint(v string) (Constraints, error) {
return Constraints(result), nil
}

// MustConstraints is a helper that wraps a call to a function
// returning (Constraints, error) and panics if error is non-nil.
func MustConstraints(c Constraints, err error) Constraints {
if err != nil {
panic(err)
}

return c
}

// Check tests if a version satisfies all the constraints.
func (cs Constraints) Check(v *Version) bool {
for _, c := range cs {
Expand Down

0 comments on commit ac9bfc9

Please sign in to comment.