gum/version/command.go
Carlos Alexandro Becker 64d69eb59b
feat(version): adds command to check current gum version (#775)
* feat(version): adds command to check current gum version

closes #352

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* Update version/command.go

Co-authored-by: Gareth Jones <Jones258@Gmail.com>

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Co-authored-by: Gareth Jones <Jones258@Gmail.com>
2024-12-13 16:59:14 -03:00

25 lines
658 B
Go

package version
import (
"fmt"
"github.com/Masterminds/semver/v3"
"github.com/alecthomas/kong"
)
// Run check that a given version matches a semantic version constraint.
func (o Options) Run(ctx *kong.Context) error {
c, err := semver.NewConstraint(o.Constraint)
if err != nil {
return fmt.Errorf("could not parse range %s: %w", o.Constraint, err)
}
current := ctx.Model.Vars()["versionNumber"]
v, err := semver.NewVersion(current)
if err != nil {
return fmt.Errorf("could not parse version %s: %w", current, err)
}
if !c.Check(v) {
return fmt.Errorf("gum version %q is not within given range %q", current, o.Constraint)
}
return nil
}