Feature request: Add semver support
Closed this issue · 2 comments
liiight commented
Please add semver support from sprig
We have a lot of use case where we need to check the minimum version of specific user tools in our tasks and we currently use grep
to do so, which is clunky.
Thanks in advance!
hoshsadiq commented
You can always add them as custom functions:
package main
import (
sv2 "github.com/Masterminds/semver/v3"
sprig "github.com/go-task/slim-sprig"
"html/template"
)
func GetFuncMap() template.FuncMap {
funcMap := sprig.FuncMap()
// add custom functions
funcMap["semver"] = semver
funcMap["semverCompare"] = semverCompare
return funcMap
}
func semverCompare(constraint, version string) (bool, error) {
c, err := sv2.NewConstraint(constraint)
if err != nil {
return false, err
}
v, err := sv2.NewVersion(version)
if err != nil {
return false, err
}
return c.Check(v), nil
}
func semver(version string) (*sv2.Version, error) {
return sv2.NewVersion(version)
}
andreynering commented
I agree. The intention of this lib is to avoid depending on external libraries as much as possible, so we don't plan to add that support.