Skip to content
Myr

command.go

This file

Path

version/command.go

26 lines · 698 bytes · Go

Last changed by

fix: lint issues (#909)Carlos Alexandro Beckerbefore adoption817c4bd

History of this file

Take it

1// Package version the version command.2package version34import (5	"fmt"67	"github.com/Masterminds/semver/v3"8	"github.com/alecthomas/kong"9)1011// Run check that a given version matches a semantic version constraint.12func (o Options) Run(ctx *kong.Context) error {13	c, err := semver.NewConstraint(o.Constraint)14	if err != nil {15		return fmt.Errorf("could not parse range %s: %w", o.Constraint, err)16	}17	current := ctx.Model.Vars()["versionNumber"]18	v, err := semver.NewVersion(current)19	if err != nil {20		return fmt.Errorf("could not parse version %s: %w", current, err)21	}22	if !c.Check(v) {23		return fmt.Errorf("gum version %q is not within given range %q", current, o.Constraint)24	}25	return nil26}