Documentation
¶
Overview ¶
Package version parses tags under a version scheme, builds the sorted set of a tool's versions, and selects the versions in a range.
Index ¶
- Constants
- Variables
- func SchemeNames() []string
- type Constraint
- type Level
- type Pick
- type Range
- type RangeOptions
- type Ref
- type Rules
- type Scheme
- type Universe
- func (u *Universe) Latest(from V, level Level) (Version, bool)
- func (u *Universe) Parse(s string) (V, error)
- func (u *Universe) ResolveConstraint(c Constraint, known []V) (V, Pick, error)
- func (u *Universe) ResolvePrefix(prefix string) (V, error)
- func (u *Universe) Scheme() Scheme
- func (u *Universe) Select(opts RangeOptions) (*Range, error)
- func (u *Universe) Versions() []Version
- type V
- type Version
Constants ¶
const ( SchemeSemver = "semver" SchemeLoose = "loose" SchemeCalver = "calver" SchemePython = "python" SchemeRegex = "regex" )
Scheme names, as used in registry entries.
Variables ¶
var ( ErrDowngrade = errors.New("range goes backwards") ErrNotFound = errors.New("version not found") ErrLineMismatch = errors.New("range leaves the release line") )
Range selection errors.
var ErrNoMatch = errors.New("no version satisfies the constraint")
ErrNoMatch is returned when no version satisfies a constraint.
var ErrParse = errors.New("invalid version")
ErrParse is wrapped by every parse error.
Functions ¶
Types ¶
type Constraint ¶
type Constraint struct {
// contains filtered or unexported fields
}
Constraint is a comma-separated list of terms that must all hold, such as "~> 1.15" or ">= 1.2, < 2". Operators: =, !=, >, >=, <, <= and ~> (pessimistic: "~> 1.15" allows 1.x from 1.15 on, "~> 1.15.3" allows 1.15.x from 1.15.3 on).
func ParseConstraint ¶
func ParseConstraint(s Scheme, expr string) (Constraint, error)
ParseConstraint parses expr with versions read under s.
func (Constraint) Check ¶
func (c Constraint) Check(v V) bool
Check reports whether v satisfies every term.
func (Constraint) Floor ¶
func (c Constraint) Floor() (V, bool)
Floor returns the lowest version c allows without a version list: its highest inclusive lower bound (=, >= or ~>), padded to three segments. The second result is false when c has no inclusive lower bound, when an exclusive bound (>) sits at or above it, or when the bound itself fails another term, as in ">= 1.5, != 1.5.0".
func (Constraint) String ¶
func (c Constraint) String() string
String returns the constraint as written.
type Level ¶
type Level string
Level is a release line granularity.
Line levels: none allows any newer version, major keeps the major, minor keeps major.minor.
type Range ¶
type Range struct {
From V // as requested
Base *Version // the version the range starts after: From, the nearest lower one, or nil
To Version
Versions []Version // (From, To], oldest first
Prereleases bool // whether prereleases were included
Warnings []string
}
Range is the result of Universe.Select.
type RangeOptions ¶
type RangeOptions struct {
From string
To string // empty means the latest stable version on the line
Line Level
IncludePrereleases bool // also on when From or To is itself a prerelease
}
RangeOptions selects the versions in (From, To].
type Ref ¶
type Ref struct {
Tag string
Draft bool
Prerelease bool // the forge's prerelease flag; the scheme can also mark one
PublishedAt time.Time
}
Ref is a tag or a release as the forge lists it.
type Rules ¶
type Rules struct {
Scheme Scheme
TagPrefix string // stripped before parsing; tags without it are dropped
TagSuffix string // stripped after the prefix, such as an image variant; tags without it are dropped
Exclude *regexp.Regexp // matched against the whole tag; matching tags are dropped
}
Rules turn tags into versions.
type Scheme ¶
type Scheme interface {
Name() string
Parse(s string) (V, error)
Compare(a, b V) int
IsPrerelease(v V) bool
Line(v V, level Level) string
}
Scheme parses and orders the versions of one tool.
func Calver ¶
func Calver() Scheme
Calver returns the calendar versioning scheme: numeric segments compared as integers ("2026.11.5", "2026.1"), with an optional "-suffix" marking a prerelease.
func Loose ¶
func Loose() Scheme
Loose returns a lenient scheme for versions that aren't semver: any number of segments ("2.35.3.1"), Go's "go1.20" and "go1.21rc2", and build metadata ("21.0.9+10", ignored when comparing).
func NewScheme ¶
NewScheme returns the named scheme. extract is the regular expression for SchemeRegex and must be empty for the others.
func Python ¶
func Python() Scheme
Python returns a PEP 440 subset: release segments, a/b/rc prereleases, .postN and .devN. Epochs and local versions are rejected.
type Universe ¶
type Universe struct {
// contains filtered or unexported fields
}
Universe is the set of a tool's versions, sorted ascending by its scheme.
func NewUniverse ¶
NewUniverse parses refs under rules. Drafts, excluded tags and tags that don't parse are dropped, and versions that compare equal ("3.7.12" and "v3.7.12") are kept once, as the first one in refs. Order comes from the scheme, never from publish dates.
func (*Universe) Latest ¶
Latest returns the newest stable version on from's release line. With LineNone or a zero from it returns the newest stable version.
func (*Universe) Parse ¶
Parse parses user input such as "1.30.0", "v1.30.0", the full tag "atlascli/v1.30.0" or the image tag "1.27.0-alpine".
func (*Universe) ResolveConstraint ¶
ResolveConstraint returns the version a constraint pin stands for: the highest of known (installed or locked versions) that satisfies c, otherwise the lowest stable version in the universe that does.
func (*Universe) ResolvePrefix ¶
ResolvePrefix returns the version a prefix pin such as "26" or "1.2" stands for: the highest stable version whose leading release segments equal the prefix, which is what mise installs.