version

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package version provides version parsing helpers shared by clive and its subpackages. It wraps hashicorp/go-version with prefix stripping, dev-version detection, and natural-sort prerelease comparison.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPrefix

func AddPrefix(v string) string

AddPrefix prepends "v" if v is non-empty and not already prefixed.

func CommitCount

func CommitCount(v string) int

CommitCount returns the number of commits since the last tag embedded in a git-describe-formatted version string (e.g. "v1.2.3-4-gabcdef[-dev]"), or 0.

func Compare

func Compare(a, b *goversion.Version) int

Compare orders two versions, using natural sort for prerelease tags so e.g. "rc2" < "rc10". Nil sorts before non-nil; two nils are equal.

func CompareString added in v0.1.10

func CompareString(a, b string) int

CompareString orders two version strings, tolerating a "v" prefix and missing trailing segments (v1.2 == 1.2.0). Git-describe/dev builds rank after their base release, since they represent commits ahead of that tag. Strings that do not parse fall back to a natural-sort comparison of their prefix-stripped forms.

func Equal

func Equal(a, b *goversion.Version) bool

Equal reports whether a and b are the same version.

func EqualString added in v0.1.6

func EqualString(a, b string) bool

EqualString reports whether two version strings denote the same version, tolerating a "v" prefix and missing trailing segments (v1.2 == 1.2.0). A string that does not parse falls back to prefix-stripped exact match, so a non-semver ref still compares.

func ExtractBase

func ExtractBase(v string) string

ExtractBase recovers the underlying release version from a dev version.

Examples:

  • "0.20.8-2-g55ae225" -> "0.20.8"
  • "0.21.3-2-g55ae225-dev" -> "0.21.3"
  • "0.21.3-3b71351-dev" -> "0.21.3"

For non-dev inputs the v-prefix is stripped and the rest returned as-is.

func GreaterThan

func GreaterThan(a, b *goversion.Version) bool

GreaterThan reports whether a > b.

func HasPrefix

func HasPrefix(v string) bool

HasPrefix reports whether v starts with a "v"/"V" version prefix.

func IsDev

func IsDev(v string) bool

IsDev reports whether v looks like a development build.

Two formats are recognised:

  • git describe: vX.Y.Z-N-gHASH (N commits ahead of tag X.Y.Z)
  • dev suffix: vX.Y.Z-HASH-dev or vX.Y.Z-N-gHASH-dev

Both indicate commits AHEAD of a tagged release, not prereleases.

func LessThan

func LessThan(a, b *goversion.Version) bool

LessThan reports whether a < b.

func Parse

func Parse(v string) (*goversion.Version, error)

Parse normalizes and parses a version string into a goversion.Version. It strips a "v" prefix and drops anything after a "-g<hash>" git suffix; go-version pads versions with fewer than three components ("1.2" -> "1.2.0").

func RemovePrefix

func RemovePrefix(v string) string

RemovePrefix strips a leading "v"/"V" if present.

Types

This section is empty.

Jump to

Keyboard shortcuts

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