func IsCompatible()

in internal/version/version.go [28:52]


func IsCompatible(constraint string) (bool, error) {
	// If either version is unspecified, it's compatible with all.
	// Think of it as not setting a compatibility restriction at all.
	if constraint == "" || cmd.Version == "" {
		return true, nil
	}

	// If the bin version is the special "latest", it always succeeds.
	// By definition there isn't a newer version.
	if cmd.Version == "latest" {
		return true, nil
	}

	binVersion, err := version.NewVersion(cmd.Version)
	if err != nil {
		return false, fmt.Errorf("interpreting binary version %q: %v", cmd.Version, err)
	}

	templateConstraint, err := version.NewConstraint(constraint)
	if err != nil {
		return false, fmt.Errorf("interpreting template version constraint %q: %v", templateConstraint, err)
	}

	return templateConstraint.Check(binVersion), nil
}