MCPcopy Create free account
hub / github.com/ddev/ddev / CheckDdevVersionConstraint

Function CheckDdevVersionConstraint

pkg/ddevapp/utils.go:563–583  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
563func 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

Callers 4

addon-get.goFile · 0.92
ValidateConfigMethod · 0.85

Calls 3

VerboseFunction · 0.92
normalizeConstraintFunction · 0.85
ErrorfMethod · 0.80

Tested by

no test coverage detected