semver

package
v1.20220411.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package semver is a fork of Hashicorp's semver package. It refactors some tests but leaves the bulk of the functionality intact.

Index

Constants

View Source
const (
	// ErrConstraintFailed is returned by validators.
	ErrConstraintFailed ex.Class = "semver; constraint failed"
)
View Source
const VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
	`(-?([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
	`(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
	`?`

VersionRegexpRaw is the raw regular expression string used for testing the validity of a version.

Variables

This section is empty.

Functions

func GreaterOrEqualTo added in v1.20210402.2

func GreaterOrEqualTo(version string) func(string) error

GreaterOrEqualTo returns a validator that enforces input versions are greater than or equal to a given version.

Strictly speaking, it returns an error if an input version is less than the given version.

Types

type Collection

type Collection []*Version

Collection is a type that implements the sort.Interface interface so that versions can be sorted.

func (Collection) Len

func (v Collection) Len() int

func (Collection) Less

func (v Collection) Less(i, j int) bool

func (Collection) Swap

func (v Collection) Swap(i, j int)

type Constraint

type Constraint struct {
	// contains filtered or unexported fields
}

Constraint represents a single constraint for a version, such as ">= 1.0".

func (*Constraint) Check

func (c *Constraint) Check(v *Version) bool

Check tests if a constraint is validated by the given version.

func (*Constraint) String

func (c *Constraint) String() string

String returns the original string.

type Constraints

type Constraints []*Constraint

Constraints is a slice of constraints. We make a custom type so that we can add methods to it.

func NewConstraint

func NewConstraint(v string) (Constraints, error)

NewConstraint will parse one or more constraints from the given constraint string. The string must be a comma-separated list of constraints.

func (Constraints) Check

func (cs Constraints) Check(v *Version) bool

Check tests if a version satisfies all the constraints.

func (Constraints) String

func (cs Constraints) String() string

Returns the string format of the constraints

type Version

type Version struct {
	// contains filtered or unexported fields
}

Version represents a single version.

func Must

func Must(v *Version, err error) *Version

Must is a helper that wraps a call to a function returning (*Version, error) and panics if error is non-nil.

func NewVersion

func NewVersion(v string) (*Version, error)

NewVersion parses the given version and returns a new Version.

func (*Version) BumpMajor

func (v *Version) BumpMajor()

BumpMajor increments the Major field by 1 and resets all other fields to their default values

func (*Version) BumpMinor

func (v *Version) BumpMinor()

BumpMinor increments the Minor field by 1 and resets all other fields to their default values

func (*Version) BumpPatch

func (v *Version) BumpPatch()

BumpPatch increments the Patch field by 1 and resets all other fields to their default values

func (*Version) Compare

func (v *Version) Compare(other *Version) int

Compare compares this version to another version. This returns -1, 0, or 1 if this version is smaller, equal, or larger than the other version, respectively.

If you want boolean results, use the LessThan, Equal, or GreaterThan methods.

func (*Version) Equal

func (v *Version) Equal(o *Version) bool

Equal tests if two versions are equal.

func (*Version) GreaterThan

func (v *Version) GreaterThan(o *Version) bool

GreaterThan tests if this version is greater than another version.

func (*Version) LessThan

func (v *Version) LessThan(o *Version) bool

LessThan tests if this version is less than another version.

func (*Version) Major

func (v *Version) Major() (major int64)

Major returns the Major segment, or the highest order segment.

func (*Version) Metadata

func (v *Version) Metadata() string

Metadata returns any metadata that was part of the version string.

Metadata is anything that comes after the "+" in the version. For example, with "1.2.3+beta", the metadata is "beta".

func (*Version) Minor

func (v *Version) Minor() (minor int64)

Minor returns the Minor segment, or the second highest order segment.

func (*Version) Patch

func (v *Version) Patch() (patch int64)

Patch returns the Patch segment, or the third highest order segment.

func (*Version) Prerelease

func (v *Version) Prerelease() string

Prerelease returns any prerelease data that is part of the version, or blank if there is no prerelease data.

Prerelease information is anything that comes after the "-" in the version (but before any metadata). For example, with "1.2.3-beta", the prerelease information is "beta".

func (*Version) Segments

func (v *Version) Segments() []int

Segments returns the numeric segments of the version as a slice of ints.

This excludes any metadata or pre-release information. For example, for a version "1.2.3-beta", segments will return a slice of 1, 2, 3.

func (*Version) Segments64

func (v *Version) Segments64() []int64

Segments64 returns the numeric segments of the version as a slice of int64s.

This excludes any metadata or pre-release information. For example, for a version "1.2.3-beta", segments will return a slice of 1, 2, 3.

func (*Version) String

func (v *Version) String() string

String returns the full version string included pre-release and metadata information.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL