version

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrVersionLessThanBase  = errors.New("version is less than the starting base version")
	ErrNoDrift              = errors.New("no version drift detected, versions are equal")
	ErrFailedVersionCompare = errors.New("failed to compare two versions")
)

Errors for operations on semantic versions.

Functions

This section is empty.

Types

type Level

type Level uint8

Level is the level of a component of a semantic version.

const (
	LevelNone Level = iota
	LevelPrerelease
	LevelPatch
	LevelMinor
	LevelMajor
)

The different level definitions for semantic version components.

type Semver

type Semver struct {
	Major      uint64
	Minor      uint64
	Patch      uint64
	Prerelease string
	Build      string
	// contains filtered or unexported fields
}

Semver represents a parsed semantic version.

func Load

func Load(version string) (Semver, error)

Load a new Semver from a semantic version string.

func (*Semver) Compare

func (s *Semver) Compare(other *Semver) int

Compare two versions to determine if one is less than (-1), equal to (0), or greater than (1) the other.

func (*Semver) Copy

func (s *Semver) Copy() *Semver

Copy the Semver into a new instance.

func (*Semver) Equals

func (s *Semver) Equals(other *Semver) bool

Equals checks whether one Semver is equal to another. Equality is determined by comparing the major/minor/patch/prerelease/build values. Since those values are all encoded into the string representation of the Semver, this just compares those strings.

func (*Semver) FindDrift

func (s *Semver) FindDrift(base *Semver) (Level, bool, error)

FindDrift finds the first instance of version drift walking down the version components.

This will return an error if the version is less than the base version it is being compared to, or if the versions are equal.

Additionally, it tracks whether the pre-release version was incremented, allowing the caller to determine whether the drift is a normal version drift (0.0.1 -> 0.0.2), a prerelease drift (0.1.0-alpha.1 -> 0.1.0-alpha.2), or a version with prerelease drift (0.1.0 -> 0.2.0-alpha.1).

func (*Semver) Increment

func (s *Semver) Increment(level Level)

Increment the Semver at the specified level.

func (*Semver) IncrementMajor

func (s *Semver) IncrementMajor()

IncrementMajor increments the major version of the Semver. In doing so, it resets lower version components, e.g. a major version bump from 0.1.2 would be 1.0.0.

func (*Semver) IncrementMinor

func (s *Semver) IncrementMinor()

IncrementMinor increments the minor version of the Semver. In doing so, it resets lower version components, e.g. a minor version bump from 0.1.2 would be 0.2.0.

func (*Semver) IncrementNew

func (s *Semver) IncrementNew(level Level) Semver

IncrementNew creates a copy of the Semver and increments the new copy at the specified level.

func (*Semver) IncrementPatch

func (s *Semver) IncrementPatch()

IncrementPatch increments the patch version of the Semver. In doing so, it resets lower version components, e.g. a patch version bump from 0.1.2 would be 0.1.3.

func (*Semver) IncrementPrerelease

func (s *Semver) IncrementPrerelease()

IncrementPrerelease increments the prerelease version of the Semver.

func (*Semver) String

func (s *Semver) String() string

String returns the string representation of the semantic version.

func (*Semver) WithVersionContext

func (s *Semver) WithVersionContext(v *Semver) *Semver

WithVersionContext adds a contextual semantic version to the Semver.

Jump to

Keyboard shortcuts

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