aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-version
diff options
context:
space:
mode:
authorNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
committerNathan Dench <ndenc2@gmail.com>2019-05-24 15:16:44 +1000
commit107c1cdb09c575aa2f61d97f48d8587eb6bada4c (patch)
treeca7d008643efc555c388baeaf1d986e0b6b3e28c /vendor/github.com/hashicorp/go-version
parent844b5a68d8af4791755b8f0ad293cc99f5959183 (diff)
downloadterraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.gz
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.tar.zst
terraform-provider-statuscake-107c1cdb09c575aa2f61d97f48d8587eb6bada4c.zip
Upgrade to 0.12
Diffstat (limited to 'vendor/github.com/hashicorp/go-version')
-rw-r--r--vendor/github.com/hashicorp/go-version/version.go35
1 files changed, 29 insertions, 6 deletions
diff --git a/vendor/github.com/hashicorp/go-version/version.go b/vendor/github.com/hashicorp/go-version/version.go
index 4d1e6e2..186fd7c 100644
--- a/vendor/github.com/hashicorp/go-version/version.go
+++ b/vendor/github.com/hashicorp/go-version/version.go
@@ -10,14 +10,25 @@ import (
10) 10)
11 11
12// The compiled regular expression used to test the validity of a version. 12// The compiled regular expression used to test the validity of a version.
13var versionRegexp *regexp.Regexp 13var (
14 versionRegexp *regexp.Regexp
15 semverRegexp *regexp.Regexp
16)
14 17
15// The raw regular expression string used for testing the validity 18// The raw regular expression string used for testing the validity
16// of a version. 19// of a version.
17const VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` + 20const (
18 `(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-?([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` + 21 VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
19 `(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` + 22 `(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-?([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` +
20 `?` 23 `(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
24 `?`
25
26 // SemverRegexpRaw requires a separator between version and prerelease
27 SemverRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
28 `(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` +
29 `(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` +
30 `?`
31)
21 32
22// Version represents a single version. 33// Version represents a single version.
23type Version struct { 34type Version struct {
@@ -30,12 +41,24 @@ type Version struct {
30 41
31func init() { 42func init() {
32 versionRegexp = regexp.MustCompile("^" + VersionRegexpRaw + "$") 43 versionRegexp = regexp.MustCompile("^" + VersionRegexpRaw + "$")
44 semverRegexp = regexp.MustCompile("^" + SemverRegexpRaw + "$")
33} 45}
34 46
35// NewVersion parses the given version and returns a new 47// NewVersion parses the given version and returns a new
36// Version. 48// Version.
37func NewVersion(v string) (*Version, error) { 49func NewVersion(v string) (*Version, error) {
38 matches := versionRegexp.FindStringSubmatch(v) 50 return newVersion(v, versionRegexp)
51}
52
53// NewSemver parses the given version and returns a new
54// Version that adheres strictly to SemVer specs
55// https://semver.org/
56func NewSemver(v string) (*Version, error) {
57 return newVersion(v, semverRegexp)
58}
59
60func newVersion(v string, pattern *regexp.Regexp) (*Version, error) {
61 matches := pattern.FindStringSubmatch(v)
39 if matches == nil { 62 if matches == nil {
40 return nil, fmt.Errorf("Malformed version: %s", v) 63 return nil, fmt.Errorf("Malformed version: %s", v)
41 } 64 }