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 ¶
- func AddPrefix(v string) string
- func CommitCount(v string) int
- func Compare(a, b *goversion.Version) int
- func CompareString(a, b string) int
- func Equal(a, b *goversion.Version) bool
- func EqualString(a, b string) bool
- func ExtractBase(v string) string
- func GreaterThan(a, b *goversion.Version) bool
- func HasPrefix(v string) bool
- func IsDev(v string) bool
- func LessThan(a, b *goversion.Version) bool
- func Parse(v string) (*goversion.Version, error)
- func RemovePrefix(v string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommitCount ¶
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 ¶
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
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 EqualString ¶ added in v0.1.6
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 ¶
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 ¶
GreaterThan reports whether a > b.
func IsDev ¶
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 Parse ¶
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 ¶
RemovePrefix strips a leading "v"/"V" if present.
Types ¶
This section is empty.