CheckDdevVersionConstraint validates if the given constraint matches the current DDEV version. If the version constraint includes pre-releases, it will normalize the constraint before checking. Returns an error if the version doesn't meet the constraint or if the constraint is invalid.
(constraint string, errorPrefix string, errorSuffix string)
| 561 | // If the version constraint includes pre-releases, it will normalize the constraint before checking. |
| 562 | // Returns an error if the version doesn't meet the constraint or if the constraint is invalid. |
| 563 | func CheckDdevVersionConstraint(constraint string, errorPrefix string, errorSuffix string) error { |
| 564 | normalizedConstraint := constraint |
| 565 | if strings.Contains(versionconstants.DdevVersion, "-") { |
| 566 | // Pre-releases need '-0' added for validation |
| 567 | normalizedConstraint = normalizeConstraint(constraint) |
| 568 | } |
| 569 | util.Verbose("Comparing constraint '%s' against version '%s'", normalizedConstraint, versionconstants.DdevVersion) |
| 570 | if errorPrefix == "" { |
| 571 | errorPrefix = "error" |
| 572 | } |
| 573 | c, err := semver.NewConstraint(normalizedConstraint) |
| 574 | if err != nil { |
| 575 | return fmt.Errorf("%s: the '%s' constraint is not valid. See https://github.com/Masterminds/semver#checking-version-constraints for valid constraints format", errorPrefix, constraint).(invalidConstraint) |
| 576 | } |
| 577 | // Make sure we do this check with valid released versions |
| 578 | v, err := semver.NewVersion(versionconstants.DdevVersion) |
| 579 | if err == nil && !c.Check(v) { |
| 580 | return fmt.Errorf("%s: your DDEV version '%s' doesn't meet the constraint '%s'. Please update to a DDEV version that meets this constraint %s", errorPrefix, versionconstants.DdevVersion, constraint, strings.TrimSpace(errorSuffix)) |
| 581 | } |
| 582 | return nil |
| 583 | } |
| 584 | |
| 585 | // normalizeConstraint adds '-0' to version expressions that don't contain a prerelease identifier |
| 586 | // See https://github.com/Masterminds/semver#working-with-prerelease-versions |
no test coverage detected