Version Properties
Setup: See /installation for one-time SDK/CLI/MCP install.
Layers: SDK (Go) → CLI (shell) → MCP (AI tools) — pick your entry point.
When to Use
- Extracting numeric segments from a version string (
[1, 2, 3])
- Getting the sub-version number embedded in a prerelease suffix (
beta2 -> 2)
- Determining the semantic weight of a suffix for ordering (
rc = 400)
- Getting the clean prefix without trailing delimiters (
"curl-" -> "curl")
- Getting the group ID used by
Group() for version grouping
Decision Tree
Need all components at once?
→ Use version_info (MCP) or version info (CLI)
Need numeric segments only?
→ Use Segments() / Segments64()
Need suffix semantic weight?
→ Use SuffixWeight() or GetSuffixWeight()
Need the group key for Group()?
→ Use BuildGroupID()
Need a clean prefix string?
→ Use Prefix.PurePrefix()
Task Patterns
Get all numeric segments
Goal: Extract the version number components as a slice.
| Layer |
Approach |
| SDK |
v.Segments(), v.Major(), v.Minor(), v.Patch() |
| CLI |
versions segments v1.2.3-rc2 |
| MCP |
{"tool": "version_info", "arguments": {"version_string": "v1.2.3-rc2"}} → major, minor, patch, version_numbers |
Determine suffix type and weight
Goal: Classify the prerelease suffix and get its ordering weight.
| Layer |
Approach |
| SDK |
v.SuffixWeight() → SuffixWeight(400); versions.GetSuffixWeight("-beta3") → beta (200) |
| CLI |
versions suffix-weight 1.2.3-rc1 |
| MCP |
{"tool": "version_info", "arguments": {"version_string": "1.2.3-rc1"}} → suffix_weight field |
Extract sub-version number from suffix
Goal: Get the numeric part of a prerelease suffix (e.g., beta2 -> 2).
| Layer |
Approach |
| SDK |
v.SubVersion() → 2 (returns 0 if suffix has no number) |
| CLI |
versions sub-version 1.2.3-beta2 |
| MCP |
{"tool": "version_info", "arguments": {"version_string": "1.2.3-beta2"}} |
Get the group ID for grouping
Goal: Obtain the key used by Group() to cluster versions.
| Layer |
Approach |
| SDK |
v.BuildGroupID() → "1.2.3" from "v1.2.3-beta1" |
| CLI |
versions group-id v1.2.3-beta1 |
| MCP |
{"tool": "version_info", "arguments": {"version_string": "v1.2.3-beta1"}} → group_id field |
Clean a prefix string
Goal: Strip trailing delimiter characters from a prefix.
| Layer |
Approach |
| SDK |
v.Prefix.PurePrefix() → "curl" from "curl-" |
| CLI |
versions pure-prefix curl-7.85.0 |
| MCP |
{"tool": "version_info", "arguments": {"version_string": "curl-7.85.0"}} |
Deep-copy a version
Goal: Create an independent copy safe for mutation.
| Layer |
Approach |
| SDK |
cloned := v.Clone() — deep copy, modifying cloned does not affect v |
| CLI |
versions clone v1.2.3 |
| MCP |
Use version_parse and reconstruct with version_build |
API Reference
SDK — Segment Accessors
v.Major() int // VersionNumbers[0] or 0
v.Minor() int // VersionNumbers[1] or 0
v.Patch() int // VersionNumbers[2] or 0
v.Segments() []int // all VersionNumbers
v.Segments64() []int64 // as int64
SDK — Suffix Properties
v.SubVersion() int // numeric from suffix (e.g. "beta2" → 2, "-beta" → 0)
v.SuffixWeight() SuffixWeight // semantic ordering weight on the Version
versions.GetSuffixWeight(s string) SuffixWeight // package-level: weight of any suffix string
Suffix weight ordering:
| Weight |
Suffix Type |
Value |
| 0 |
unknown (no suffix / unclassified) |
0 |
| 50 |
dev |
50 |
| 60 |
snapshot |
60 |
| 70 |
nightly |
70 |
| 100 |
alpha |
100 |
| 200 |
beta |
200 |
| 300 |
milestone |
300 |
| 400 |
rc |
400 |
| 500 |
final / release / ga |
500 |
| 600 |
sp |
600 |
| 700 |
patch |
700 |
| 800 |
post |
800 |
SDK — Prefix, Group, Clone, Serialization
v.Prefix.PurePrefix() string // prefix without trailing delimiters, e.g. "curl-" → "curl"
v.BuildGroupID() string // group key, e.g. "v1.2.3-beta1" → "1.2.3"
v.Clone() *Version // deep copy, independent of original
v.RawString() string // original parsed string (human-readable, unlike String())
CLI Commands
versions segments <v> # {"segments": [1, 2, 3]}
versions sub-version <v> # {"sub_version": 2}
versions suffix-weight <v> # {"suffix_weight": "rc", "weight_value": 400}
versions pure-prefix <v> # {"prefix": "curl-", "pure_prefix": "curl"}
versions group-id <v> # {"group_id": "1.2.3"}
versions clone <v> # full version object as JSON
MCP Tools
| Tool |
Arguments |
Returns |
version_info |
version_string |
raw, valid, major, minor, patch, version_numbers, prefix, suffix, suffix_weight, group_id, all Is* flags |
Cross-References
- [[version-check]] — boolean checks on version type (IsBeta, IsStable, etc.)
- [[version-grouping]] — Group() uses BuildGroupID() for clustering
- [[version-comparison]] — CompareTo uses SuffixWeight for ordering
- [[version-mutation]] — modify version components after inspecting them
Important Notes
- Suffix weight order: dev(50) < snapshot(60) < nightly(70) < alpha(100) < beta(200) < milestone(300) < rc(400) < final/release/ga(500) < sp(600) < patch(700) < post(800)
- SubVersion() returns 0 if the suffix has no numeric part (
"-beta" -> 0, "-beta2" -> 2).
- PurePrefix() strips trailing
-, ., _ — use it to extract a clean package name.
- BuildGroupID() is the key for
Group() — versions differing only by suffix share the same group.
- Clone() creates a fully independent deep copy — safe for concurrent modification.
- RawString() returns the original parsed string; String() returns a different (JSON) format.
1---2name: version-properties3description: Extract segments, sub-version, suffix weight, pure prefix, or group ID from a parsed version.4---56# Version Properties78> **Setup:** See `/installation` for one-time SDK/CLI/MCP install. 9> **Layers:** SDK (Go) → CLI (shell) → MCP (AI tools) — pick your entry point.1011## When to Use1213- Extracting numeric segments from a version string (`[1, 2, 3]`)14- Getting the sub-version number embedded in a prerelease suffix (`beta2` -> `2`)15- Determining the semantic weight of a suffix for ordering (`rc` = 400)16- Getting the clean prefix without trailing delimiters (`"curl-"` -> `"curl"`)17- Getting the group ID used by `Group()` for version grouping1819## Decision Tree2021```22Need all components at once?23 → Use version_info (MCP) or version info (CLI)24Need numeric segments only?25 → Use Segments() / Segments64()26Need suffix semantic weight?27 → Use SuffixWeight() or GetSuffixWeight()28Need the group key for Group()?29 → Use BuildGroupID()30Need a clean prefix string?31 → Use Prefix.PurePrefix()32```3334## Task Patterns3536### Get all numeric segments3738**Goal:** Extract the version number components as a slice.3940| Layer | Approach |41|-------|----------|42| SDK | `v.Segments()`, `v.Major()`, `v.Minor()`, `v.Patch()` |43| CLI | `versions segments v1.2.3-rc2` |44| MCP | `{"tool": "version_info", "arguments": {"version_string": "v1.2.3-rc2"}}` → major, minor, patch, version_numbers |4546### Determine suffix type and weight4748**Goal:** Classify the prerelease suffix and get its ordering weight.4950| Layer | Approach |51|-------|----------|52| SDK | `v.SuffixWeight()` → SuffixWeight(400); `versions.GetSuffixWeight("-beta3")` → beta (200) |53| CLI | `versions suffix-weight 1.2.3-rc1` |54| MCP | `{"tool": "version_info", "arguments": {"version_string": "1.2.3-rc1"}}` → suffix_weight field |5556### Extract sub-version number from suffix5758**Goal:** Get the numeric part of a prerelease suffix (e.g., `beta2` -> `2`).5960| Layer | Approach |61|-------|----------|62| SDK | `v.SubVersion()` → 2 (returns 0 if suffix has no number) |63| CLI | `versions sub-version 1.2.3-beta2` |64| MCP | `{"tool": "version_info", "arguments": {"version_string": "1.2.3-beta2"}}` |6566### Get the group ID for grouping6768**Goal:** Obtain the key used by `Group()` to cluster versions.6970| Layer | Approach |71|-------|----------|72| SDK | `v.BuildGroupID()` → `"1.2.3"` from `"v1.2.3-beta1"` |73| CLI | `versions group-id v1.2.3-beta1` |74| MCP | `{"tool": "version_info", "arguments": {"version_string": "v1.2.3-beta1"}}` → group_id field |7576### Clean a prefix string7778**Goal:** Strip trailing delimiter characters from a prefix.7980| Layer | Approach |81|-------|----------|82| SDK | `v.Prefix.PurePrefix()` → `"curl"` from `"curl-"` |83| CLI | `versions pure-prefix curl-7.85.0` |84| MCP | `{"tool": "version_info", "arguments": {"version_string": "curl-7.85.0"}}` |8586### Deep-copy a version8788**Goal:** Create an independent copy safe for mutation.8990| Layer | Approach |91|-------|----------|92| SDK | `cloned := v.Clone()` — deep copy, modifying cloned does not affect v |93| CLI | `versions clone v1.2.3` |94| MCP | Use `version_parse` and reconstruct with `version_build` |9596## API Reference9798### SDK — Segment Accessors99100```go101v.Major() int // VersionNumbers[0] or 0102v.Minor() int // VersionNumbers[1] or 0103v.Patch() int // VersionNumbers[2] or 0104v.Segments() []int // all VersionNumbers105v.Segments64() []int64 // as int64106```107108### SDK — Suffix Properties109110```go111v.SubVersion() int // numeric from suffix (e.g. "beta2" → 2, "-beta" → 0)112v.SuffixWeight() SuffixWeight // semantic ordering weight on the Version113versions.GetSuffixWeight(s string) SuffixWeight // package-level: weight of any suffix string114```115116Suffix weight ordering:117118| Weight | Suffix Type | Value |119|--------|------------|-------|120| 0 | unknown (no suffix / unclassified) | 0 |121| 50 | dev | 50 |122| 60 | snapshot | 60 |123| 70 | nightly | 70 |124| 100 | alpha | 100 |125| 200 | beta | 200 |126| 300 | milestone | 300 |127| 400 | rc | 400 |128| 500 | final / release / ga | 500 |129| 600 | sp | 600 |130| 700 | patch | 700 |131| 800 | post | 800 |132133### SDK — Prefix, Group, Clone, Serialization134135```go136v.Prefix.PurePrefix() string // prefix without trailing delimiters, e.g. "curl-" → "curl"137v.BuildGroupID() string // group key, e.g. "v1.2.3-beta1" → "1.2.3"138v.Clone() *Version // deep copy, independent of original139v.RawString() string // original parsed string (human-readable, unlike String())140```141142### CLI Commands143144```bash145versions segments <v> # {"segments": [1, 2, 3]}146versions sub-version <v> # {"sub_version": 2}147versions suffix-weight <v> # {"suffix_weight": "rc", "weight_value": 400}148versions pure-prefix <v> # {"prefix": "curl-", "pure_prefix": "curl"}149versions group-id <v> # {"group_id": "1.2.3"}150versions clone <v> # full version object as JSON151```152153### MCP Tools154155| Tool | Arguments | Returns |156|------|-----------|---------|157| `version_info` | `version_string` | raw, valid, major, minor, patch, version_numbers, prefix, suffix, suffix_weight, group_id, all Is* flags |158159## Cross-References160161- [[version-check]] — boolean checks on version type (IsBeta, IsStable, etc.)162- [[version-grouping]] — Group() uses BuildGroupID() for clustering163- [[version-comparison]] — CompareTo uses SuffixWeight for ordering164- [[version-mutation]] — modify version components after inspecting them165166## Important Notes167168- **Suffix weight order**: dev(50) < snapshot(60) < nightly(70) < alpha(100) < beta(200) < milestone(300) < rc(400) < final/release/ga(500) < sp(600) < patch(700) < post(800)169- **SubVersion() returns 0** if the suffix has no numeric part (`"-beta"` -> `0`, `"-beta2"` -> `2`).170- **PurePrefix() strips trailing `-`, `.`, `_`** — use it to extract a clean package name.171- **BuildGroupID()** is the key for `Group()` — versions differing only by suffix share the same group.172- **Clone() creates a fully independent deep copy** — safe for concurrent modification.173- **RawString()** returns the original parsed string; **String()** returns a different (JSON) format.