File: command.go

package info (click to toggle)
gum 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 668 kB
  • sloc: sh: 232; ruby: 24; makefile: 17; javascript: 9; python: 4
file content (26 lines) | stat: -rw-r--r-- 698 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// 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
}