diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-version')
-rw-r--r-- | vendor/github.com/hashicorp/go-version/.travis.yml | 2 | ||||
-rw-r--r-- | vendor/github.com/hashicorp/go-version/constraint.go | 34 | ||||
-rw-r--r-- | vendor/github.com/hashicorp/go-version/go.mod | 1 | ||||
-rw-r--r-- | vendor/github.com/hashicorp/go-version/version.go | 59 |
4 files changed, 82 insertions, 14 deletions
diff --git a/vendor/github.com/hashicorp/go-version/.travis.yml b/vendor/github.com/hashicorp/go-version/.travis.yml index 9f30eec..542ca8b 100644 --- a/vendor/github.com/hashicorp/go-version/.travis.yml +++ b/vendor/github.com/hashicorp/go-version/.travis.yml | |||
@@ -6,6 +6,8 @@ go: | |||
6 | - 1.2 | 6 | - 1.2 |
7 | - 1.3 | 7 | - 1.3 |
8 | - 1.4 | 8 | - 1.4 |
9 | - 1.9 | ||
10 | - "1.10" | ||
9 | 11 | ||
10 | script: | 12 | script: |
11 | - go test | 13 | - go test |
diff --git a/vendor/github.com/hashicorp/go-version/constraint.go b/vendor/github.com/hashicorp/go-version/constraint.go index 8c73df0..d055759 100644 --- a/vendor/github.com/hashicorp/go-version/constraint.go +++ b/vendor/github.com/hashicorp/go-version/constraint.go | |||
@@ -2,6 +2,7 @@ package version | |||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "fmt" | 4 | "fmt" |
5 | "reflect" | ||
5 | "regexp" | 6 | "regexp" |
6 | "strings" | 7 | "strings" |
7 | ) | 8 | ) |
@@ -113,6 +114,26 @@ func parseSingle(v string) (*Constraint, error) { | |||
113 | }, nil | 114 | }, nil |
114 | } | 115 | } |
115 | 116 | ||
117 | func prereleaseCheck(v, c *Version) bool { | ||
118 | switch vPre, cPre := v.Prerelease() != "", c.Prerelease() != ""; { | ||
119 | case cPre && vPre: | ||
120 | // A constraint with a pre-release can only match a pre-release version | ||
121 | // with the same base segments. | ||
122 | return reflect.DeepEqual(c.Segments64(), v.Segments64()) | ||
123 | |||
124 | case !cPre && vPre: | ||
125 | // A constraint without a pre-release can only match a version without a | ||
126 | // pre-release. | ||
127 | return false | ||
128 | |||
129 | case cPre && !vPre: | ||
130 | // OK, except with the pessimistic operator | ||
131 | case !cPre && !vPre: | ||
132 | // OK | ||
133 | } | ||
134 | return true | ||
135 | } | ||
136 | |||
116 | //------------------------------------------------------------------- | 137 | //------------------------------------------------------------------- |
117 | // Constraint functions | 138 | // Constraint functions |
118 | //------------------------------------------------------------------- | 139 | //------------------------------------------------------------------- |
@@ -126,22 +147,27 @@ func constraintNotEqual(v, c *Version) bool { | |||
126 | } | 147 | } |
127 | 148 | ||
128 | func constraintGreaterThan(v, c *Version) bool { | 149 | func constraintGreaterThan(v, c *Version) bool { |
129 | return v.Compare(c) == 1 | 150 | return prereleaseCheck(v, c) && v.Compare(c) == 1 |
130 | } | 151 | } |
131 | 152 | ||
132 | func constraintLessThan(v, c *Version) bool { | 153 | func constraintLessThan(v, c *Version) bool { |
133 | return v.Compare(c) == -1 | 154 | return prereleaseCheck(v, c) && v.Compare(c) == -1 |
134 | } | 155 | } |
135 | 156 | ||
136 | func constraintGreaterThanEqual(v, c *Version) bool { | 157 | func constraintGreaterThanEqual(v, c *Version) bool { |
137 | return v.Compare(c) >= 0 | 158 | return prereleaseCheck(v, c) && v.Compare(c) >= 0 |
138 | } | 159 | } |
139 | 160 | ||
140 | func constraintLessThanEqual(v, c *Version) bool { | 161 | func constraintLessThanEqual(v, c *Version) bool { |
141 | return v.Compare(c) <= 0 | 162 | return prereleaseCheck(v, c) && v.Compare(c) <= 0 |
142 | } | 163 | } |
143 | 164 | ||
144 | func constraintPessimistic(v, c *Version) bool { | 165 | func constraintPessimistic(v, c *Version) bool { |
166 | // Using a pessimistic constraint with a pre-release, restricts versions to pre-releases | ||
167 | if !prereleaseCheck(v, c) || (c.Prerelease() != "" && v.Prerelease() == "") { | ||
168 | return false | ||
169 | } | ||
170 | |||
145 | // If the version being checked is naturally less than the constraint, then there | 171 | // If the version being checked is naturally less than the constraint, then there |
146 | // is no way for the version to be valid against the constraint | 172 | // is no way for the version to be valid against the constraint |
147 | if v.LessThan(c) { | 173 | if v.LessThan(c) { |
diff --git a/vendor/github.com/hashicorp/go-version/go.mod b/vendor/github.com/hashicorp/go-version/go.mod new file mode 100644 index 0000000..f528555 --- /dev/null +++ b/vendor/github.com/hashicorp/go-version/go.mod | |||
@@ -0,0 +1 @@ | |||
module github.com/hashicorp/go-version | |||
diff --git a/vendor/github.com/hashicorp/go-version/version.go b/vendor/github.com/hashicorp/go-version/version.go index ae2f6b6..4d1e6e2 100644 --- a/vendor/github.com/hashicorp/go-version/version.go +++ b/vendor/github.com/hashicorp/go-version/version.go | |||
@@ -15,8 +15,8 @@ var versionRegexp *regexp.Regexp | |||
15 | // The raw regular expression string used for testing the validity | 15 | // The raw regular expression string used for testing the validity |
16 | // of a version. | 16 | // of a version. |
17 | const VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` + | 17 | const VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` + |
18 | `(-?([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` + | 18 | `(-([0-9]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)|(-?([A-Za-z\-~]+[0-9A-Za-z\-~]*(\.[0-9A-Za-z\-~]+)*)))?` + |
19 | `(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` + | 19 | `(\+([0-9A-Za-z\-~]+(\.[0-9A-Za-z\-~]+)*))?` + |
20 | `?` | 20 | `?` |
21 | 21 | ||
22 | // Version represents a single version. | 22 | // Version represents a single version. |
@@ -25,6 +25,7 @@ type Version struct { | |||
25 | pre string | 25 | pre string |
26 | segments []int64 | 26 | segments []int64 |
27 | si int | 27 | si int |
28 | original string | ||
28 | } | 29 | } |
29 | 30 | ||
30 | func init() { | 31 | func init() { |
@@ -59,11 +60,17 @@ func NewVersion(v string) (*Version, error) { | |||
59 | segments = append(segments, 0) | 60 | segments = append(segments, 0) |
60 | } | 61 | } |
61 | 62 | ||
63 | pre := matches[7] | ||
64 | if pre == "" { | ||
65 | pre = matches[4] | ||
66 | } | ||
67 | |||
62 | return &Version{ | 68 | return &Version{ |
63 | metadata: matches[7], | 69 | metadata: matches[10], |
64 | pre: matches[4], | 70 | pre: pre, |
65 | segments: segments, | 71 | segments: segments, |
66 | si: si, | 72 | si: si, |
73 | original: v, | ||
67 | }, nil | 74 | }, nil |
68 | } | 75 | } |
69 | 76 | ||
@@ -166,24 +173,42 @@ func comparePart(preSelf string, preOther string) int { | |||
166 | return 0 | 173 | return 0 |
167 | } | 174 | } |
168 | 175 | ||
176 | var selfInt int64 | ||
177 | selfNumeric := true | ||
178 | selfInt, err := strconv.ParseInt(preSelf, 10, 64) | ||
179 | if err != nil { | ||
180 | selfNumeric = false | ||
181 | } | ||
182 | |||
183 | var otherInt int64 | ||
184 | otherNumeric := true | ||
185 | otherInt, err = strconv.ParseInt(preOther, 10, 64) | ||
186 | if err != nil { | ||
187 | otherNumeric = false | ||
188 | } | ||
189 | |||
169 | // if a part is empty, we use the other to decide | 190 | // if a part is empty, we use the other to decide |
170 | if preSelf == "" { | 191 | if preSelf == "" { |
171 | _, notIsNumeric := strconv.ParseInt(preOther, 10, 64) | 192 | if otherNumeric { |
172 | if notIsNumeric == nil { | ||
173 | return -1 | 193 | return -1 |
174 | } | 194 | } |
175 | return 1 | 195 | return 1 |
176 | } | 196 | } |
177 | 197 | ||
178 | if preOther == "" { | 198 | if preOther == "" { |
179 | _, notIsNumeric := strconv.ParseInt(preSelf, 10, 64) | 199 | if selfNumeric { |
180 | if notIsNumeric == nil { | ||
181 | return 1 | 200 | return 1 |
182 | } | 201 | } |
183 | return -1 | 202 | return -1 |
184 | } | 203 | } |
185 | 204 | ||
186 | if preSelf > preOther { | 205 | if selfNumeric && !otherNumeric { |
206 | return -1 | ||
207 | } else if !selfNumeric && otherNumeric { | ||
208 | return 1 | ||
209 | } else if !selfNumeric && !otherNumeric && preSelf > preOther { | ||
210 | return 1 | ||
211 | } else if selfInt > otherInt { | ||
187 | return 1 | 212 | return 1 |
188 | } | 213 | } |
189 | 214 | ||
@@ -283,11 +308,19 @@ func (v *Version) Segments() []int { | |||
283 | // for a version "1.2.3-beta", segments will return a slice of | 308 | // for a version "1.2.3-beta", segments will return a slice of |
284 | // 1, 2, 3. | 309 | // 1, 2, 3. |
285 | func (v *Version) Segments64() []int64 { | 310 | func (v *Version) Segments64() []int64 { |
286 | return v.segments | 311 | result := make([]int64, len(v.segments)) |
312 | copy(result, v.segments) | ||
313 | return result | ||
287 | } | 314 | } |
288 | 315 | ||
289 | // String returns the full version string included pre-release | 316 | // String returns the full version string included pre-release |
290 | // and metadata information. | 317 | // and metadata information. |
318 | // | ||
319 | // This value is rebuilt according to the parsed segments and other | ||
320 | // information. Therefore, ambiguities in the version string such as | ||
321 | // prefixed zeroes (1.04.0 => 1.4.0), `v` prefix (v1.0.0 => 1.0.0), and | ||
322 | // missing parts (1.0 => 1.0.0) will be made into a canonicalized form | ||
323 | // as shown in the parenthesized examples. | ||
291 | func (v *Version) String() string { | 324 | func (v *Version) String() string { |
292 | var buf bytes.Buffer | 325 | var buf bytes.Buffer |
293 | fmtParts := make([]string, len(v.segments)) | 326 | fmtParts := make([]string, len(v.segments)) |
@@ -306,3 +339,9 @@ func (v *Version) String() string { | |||
306 | 339 | ||
307 | return buf.String() | 340 | return buf.String() |
308 | } | 341 | } |
342 | |||
343 | // Original returns the original parsed version as-is, including any | ||
344 | // potential whitespace, `v` prefix, etc. | ||
345 | func (v *Version) Original() string { | ||
346 | return v.original | ||
347 | } | ||