mirror of
https://github.com/charmbracelet/gum
synced 2026-03-14 21:55:45 +01:00
26 lines
698 B
Go
26 lines
698 B
Go
// Package version the version command.
|
|
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
|
|
}
|