diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-version/version.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-version/version.go | 59 |
1 files changed, 49 insertions, 10 deletions
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 | } | ||