diff options
| author | wuhuizuo <wuhuizuo@126.com> | 2023-11-25 00:21:01 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-24 16:21:01 +0000 |
| commit | 635e78c38aa1cb0f31efff7f5cb0eecfe93f505c (patch) | |
| tree | 6bbdfebc1bb28c7e90e7b1a82d04f59adfb330af /docs | |
| parent | dba98c6d51f327959bf43691032ca16cee599264 (diff) | |
feat(funcs): add semver functions (#1829)
* feat(funcs): add semver functions
- semver.Version: new a SemVer struct.
- semver.MatchConstraint: match in arg with semver constraint string.
refer to: https://github.com/Masterminds/sprig/blob/master/semver.go
* docs(functions): add documents for semver functions
* Update docs-src/content/functions/semver.yaml
Co-authored-by: Dave Henderson <dhenderson@gmail.com>
* fix(funcs,docs,docs-src): fix the reviewing issues
---------
Co-authored-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/content/functions/semver.md | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/docs/content/functions/semver.md b/docs/content/functions/semver.md new file mode 100644 index 00000000..b94488ff --- /dev/null +++ b/docs/content/functions/semver.md @@ -0,0 +1,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 matchs 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 +``` |
