blob: 03c97ea4659e582f875436c5bc68184e41b93675 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
---
title: semver functions
menu:
main:
parent: functions
---
These functions allow user you to parse a [semantic version](http://semver.org/) string or test it with constraint.
It's implemented with the https://github.com/Masterminds/semver library.
## `semver.Semver`_(unreleased)_
**Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
Returns a semantic version struct holding the `input` version string.
The returned struct are defined at: [`semver.Version`](https://pkg.go.dev/github.com/Masterminds/semver/v3#Version).
### Usage
```
semver.Semver input
```
```
input | semver.Semver
```
### Arguments
| name | description |
|------|-------------|
| `input` | _(required)_ The input to parse |
### Examples
```console
$ gomplate -i '{{ semver.Semver "v1.1.1"}}'
1.1.1
```
```console
$ gomplate -i '{{ (semver.Semver "v1.1.1").Major }}'
1
```
```console
$ gomplate -i 'the pre release version is {{ ("v1.1.1" | semver.Semver).SetPrerelease "beta.1" }}'
the pre release version is 1.1.1-beta.1
```
## `semver.CheckConstraint`_(unreleased)_
**Unreleased:** _This function is in development, and not yet available in released builds of gomplate._
Test whether the input version matches the constraint.
Ref: https://github.com/Masterminds/semver#checking-version-constraints
### Usage
```
semver.CheckConstraint constraint input
```
```
input | semver.CheckConstraint constraint
```
### Arguments
| name | description |
|------|-------------|
| `constraint` | _(required)_ The constraints expression to test. |
| `input` | _(required)_ The input semantic version string to test. |
### Examples
```console
$ gomplate -i '{{ semver.CheckConstraint "> 1.0" "v1.1.1" }}'
true
```
```console
$ gomplate -i '{{ semver.CheckConstraint "> 1.0, <1.1" "v1.1.1" }}'
false
```
```console
$ gomplate -i '{{ "v1.1.1" | semver.CheckConstraint "> 1.0" }}'
true
```
|