aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/go-version
diff options
context:
space:
mode:
authorJake Champlin <jake.champlin.27@gmail.com>2017-06-06 12:40:07 -0400
committerJake Champlin <jake.champlin.27@gmail.com>2017-06-06 12:40:07 -0400
commitbae9f6d2fd5eb5bc80929bd393932b23f14d7c93 (patch)
treeca9ab12a7d78b1fc27a8f734729081357ce6d252 /vendor/github.com/hashicorp/go-version
parent254c495b6bebab3fb72a243c4bce858d79e6ee99 (diff)
downloadterraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.gz
terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.tar.zst
terraform-provider-statuscake-bae9f6d2fd5eb5bc80929bd393932b23f14d7c93.zip
Initial transfer of provider code
Diffstat (limited to 'vendor/github.com/hashicorp/go-version')
-rw-r--r--vendor/github.com/hashicorp/go-version/LICENSE354
-rw-r--r--vendor/github.com/hashicorp/go-version/README.md65
-rw-r--r--vendor/github.com/hashicorp/go-version/constraint.go178
-rw-r--r--vendor/github.com/hashicorp/go-version/version.go308
-rw-r--r--vendor/github.com/hashicorp/go-version/version_collection.go17
5 files changed, 922 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-version/LICENSE b/vendor/github.com/hashicorp/go-version/LICENSE
new file mode 100644
index 0000000..c33dcc7
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-version/LICENSE
@@ -0,0 +1,354 @@
1Mozilla Public License, version 2.0
2
31. Definitions
4
51.1. “Contributor”
6
7 means each individual or legal entity that creates, contributes to the
8 creation of, or owns Covered Software.
9
101.2. “Contributor Version”
11
12 means the combination of the Contributions of others (if any) used by a
13 Contributor and that particular Contributor’s Contribution.
14
151.3. “Contribution”
16
17 means Covered Software of a particular Contributor.
18
191.4. “Covered Software”
20
21 means Source Code Form to which the initial Contributor has attached the
22 notice in Exhibit A, the Executable Form of such Source Code Form, and
23 Modifications of such Source Code Form, in each case including portions
24 thereof.
25
261.5. “Incompatible With Secondary Licenses”
27 means
28
29 a. that the initial Contributor has attached the notice described in
30 Exhibit B to the Covered Software; or
31
32 b. that the Covered Software was made available under the terms of version
33 1.1 or earlier of the License, but not also under the terms of a
34 Secondary License.
35
361.6. “Executable Form”
37
38 means any form of the work other than Source Code Form.
39
401.7. “Larger Work”
41
42 means a work that combines Covered Software with other material, in a separate
43 file or files, that is not Covered Software.
44
451.8. “License”
46
47 means this document.
48
491.9. “Licensable”
50
51 means having the right to grant, to the maximum extent possible, whether at the
52 time of the initial grant or subsequently, any and all of the rights conveyed by
53 this License.
54
551.10. “Modifications”
56
57 means any of the following:
58
59 a. any file in Source Code Form that results from an addition to, deletion
60 from, or modification of the contents of Covered Software; or
61
62 b. any new file in Source Code Form that contains any Covered Software.
63
641.11. “Patent Claims” of a Contributor
65
66 means any patent claim(s), including without limitation, method, process,
67 and apparatus claims, in any patent Licensable by such Contributor that
68 would be infringed, but for the grant of the License, by the making,
69 using, selling, offering for sale, having made, import, or transfer of
70 either its Contributions or its Contributor Version.
71
721.12. “Secondary License”
73
74 means either the GNU General Public License, Version 2.0, the GNU Lesser
75 General Public License, Version 2.1, the GNU Affero General Public
76 License, Version 3.0, or any later versions of those licenses.
77
781.13. “Source Code Form”
79
80 means the form of the work preferred for making modifications.
81
821.14. “You” (or “Your”)
83
84 means an individual or a legal entity exercising rights under this
85 License. For legal entities, “You” includes any entity that controls, is
86 controlled by, or is under common control with You. For purposes of this
87 definition, “control” means (a) the power, direct or indirect, to cause
88 the direction or management of such entity, whether by contract or
89 otherwise, or (b) ownership of more than fifty percent (50%) of the
90 outstanding shares or beneficial ownership of such entity.
91
92
932. License Grants and Conditions
94
952.1. Grants
96
97 Each Contributor hereby grants You a world-wide, royalty-free,
98 non-exclusive license:
99
100 a. under intellectual property rights (other than patent or trademark)
101 Licensable by such Contributor to use, reproduce, make available,
102 modify, display, perform, distribute, and otherwise exploit its
103 Contributions, either on an unmodified basis, with Modifications, or as
104 part of a Larger Work; and
105
106 b. under Patent Claims of such Contributor to make, use, sell, offer for
107 sale, have made, import, and otherwise transfer either its Contributions
108 or its Contributor Version.
109
1102.2. Effective Date
111
112 The licenses granted in Section 2.1 with respect to any Contribution become
113 effective for each Contribution on the date the Contributor first distributes
114 such Contribution.
115
1162.3. Limitations on Grant Scope
117
118 The licenses granted in this Section 2 are the only rights granted under this
119 License. No additional rights or licenses will be implied from the distribution
120 or licensing of Covered Software under this License. Notwithstanding Section
121 2.1(b) above, no patent license is granted by a Contributor:
122
123 a. for any code that a Contributor has removed from Covered Software; or
124
125 b. for infringements caused by: (i) Your and any other third party’s
126 modifications of Covered Software, or (ii) the combination of its
127 Contributions with other software (except as part of its Contributor
128 Version); or
129
130 c. under Patent Claims infringed by Covered Software in the absence of its
131 Contributions.
132
133 This License does not grant any rights in the trademarks, service marks, or
134 logos of any Contributor (except as may be necessary to comply with the
135 notice requirements in Section 3.4).
136
1372.4. Subsequent Licenses
138
139 No Contributor makes additional grants as a result of Your choice to
140 distribute the Covered Software under a subsequent version of this License
141 (see Section 10.2) or under the terms of a Secondary License (if permitted
142 under the terms of Section 3.3).
143
1442.5. Representation
145
146 Each Contributor represents that the Contributor believes its Contributions
147 are its original creation(s) or it has sufficient rights to grant the
148 rights to its Contributions conveyed by this License.
149
1502.6. Fair Use
151
152 This License is not intended to limit any rights You have under applicable
153 copyright doctrines of fair use, fair dealing, or other equivalents.
154
1552.7. Conditions
156
157 Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
158 Section 2.1.
159
160
1613. Responsibilities
162
1633.1. Distribution of Source Form
164
165 All distribution of Covered Software in Source Code Form, including any
166 Modifications that You create or to which You contribute, must be under the
167 terms of this License. You must inform recipients that the Source Code Form
168 of the Covered Software is governed by the terms of this License, and how
169 they can obtain a copy of this License. You may not attempt to alter or
170 restrict the recipients’ rights in the Source Code Form.
171
1723.2. Distribution of Executable Form
173
174 If You distribute Covered Software in Executable Form then:
175
176 a. such Covered Software must also be made available in Source Code Form,
177 as described in Section 3.1, and You must inform recipients of the
178 Executable Form how they can obtain a copy of such Source Code Form by
179 reasonable means in a timely manner, at a charge no more than the cost
180 of distribution to the recipient; and
181
182 b. You may distribute such Executable Form under the terms of this License,
183 or sublicense it under different terms, provided that the license for
184 the Executable Form does not attempt to limit or alter the recipients’
185 rights in the Source Code Form under this License.
186
1873.3. Distribution of a Larger Work
188
189 You may create and distribute a Larger Work under terms of Your choice,
190 provided that You also comply with the requirements of this License for the
191 Covered Software. If the Larger Work is a combination of Covered Software
192 with a work governed by one or more Secondary Licenses, and the Covered
193 Software is not Incompatible With Secondary Licenses, this License permits
194 You to additionally distribute such Covered Software under the terms of
195 such Secondary License(s), so that the recipient of the Larger Work may, at
196 their option, further distribute the Covered Software under the terms of
197 either this License or such Secondary License(s).
198
1993.4. Notices
200
201 You may not remove or alter the substance of any license notices (including
202 copyright notices, patent notices, disclaimers of warranty, or limitations
203 of liability) contained within the Source Code Form of the Covered
204 Software, except that You may alter any license notices to the extent
205 required to remedy known factual inaccuracies.
206
2073.5. Application of Additional Terms
208
209 You may choose to offer, and to charge a fee for, warranty, support,
210 indemnity or liability obligations to one or more recipients of Covered
211 Software. However, You may do so only on Your own behalf, and not on behalf
212 of any Contributor. You must make it absolutely clear that any such
213 warranty, support, indemnity, or liability obligation is offered by You
214 alone, and You hereby agree to indemnify every Contributor for any
215 liability incurred by such Contributor as a result of warranty, support,
216 indemnity or liability terms You offer. You may include additional
217 disclaimers of warranty and limitations of liability specific to any
218 jurisdiction.
219
2204. Inability to Comply Due to Statute or Regulation
221
222 If it is impossible for You to comply with any of the terms of this License
223 with respect to some or all of the Covered Software due to statute, judicial
224 order, or regulation then You must: (a) comply with the terms of this License
225 to the maximum extent possible; and (b) describe the limitations and the code
226 they affect. Such description must be placed in a text file included with all
227 distributions of the Covered Software under this License. Except to the
228 extent prohibited by statute or regulation, such description must be
229 sufficiently detailed for a recipient of ordinary skill to be able to
230 understand it.
231
2325. Termination
233
2345.1. The rights granted under this License will terminate automatically if You
235 fail to comply with any of its terms. However, if You become compliant,
236 then the rights granted under this License from a particular Contributor
237 are reinstated (a) provisionally, unless and until such Contributor
238 explicitly and finally terminates Your grants, and (b) on an ongoing basis,
239 if such Contributor fails to notify You of the non-compliance by some
240 reasonable means prior to 60 days after You have come back into compliance.
241 Moreover, Your grants from a particular Contributor are reinstated on an
242 ongoing basis if such Contributor notifies You of the non-compliance by
243 some reasonable means, this is the first time You have received notice of
244 non-compliance with this License from such Contributor, and You become
245 compliant prior to 30 days after Your receipt of the notice.
246
2475.2. If You initiate litigation against any entity by asserting a patent
248 infringement claim (excluding declaratory judgment actions, counter-claims,
249 and cross-claims) alleging that a Contributor Version directly or
250 indirectly infringes any patent, then the rights granted to You by any and
251 all Contributors for the Covered Software under Section 2.1 of this License
252 shall terminate.
253
2545.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
255 license agreements (excluding distributors and resellers) which have been
256 validly granted by You or Your distributors under this License prior to
257 termination shall survive termination.
258
2596. Disclaimer of Warranty
260
261 Covered Software is provided under this License on an “as is” basis, without
262 warranty of any kind, either expressed, implied, or statutory, including,
263 without limitation, warranties that the Covered Software is free of defects,
264 merchantable, fit for a particular purpose or non-infringing. The entire
265 risk as to the quality and performance of the Covered Software is with You.
266 Should any Covered Software prove defective in any respect, You (not any
267 Contributor) assume the cost of any necessary servicing, repair, or
268 correction. This disclaimer of warranty constitutes an essential part of this
269 License. No use of any Covered Software is authorized under this License
270 except under this disclaimer.
271
2727. Limitation of Liability
273
274 Under no circumstances and under no legal theory, whether tort (including
275 negligence), contract, or otherwise, shall any Contributor, or anyone who
276 distributes Covered Software as permitted above, be liable to You for any
277 direct, indirect, special, incidental, or consequential damages of any
278 character including, without limitation, damages for lost profits, loss of
279 goodwill, work stoppage, computer failure or malfunction, or any and all
280 other commercial damages or losses, even if such party shall have been
281 informed of the possibility of such damages. This limitation of liability
282 shall not apply to liability for death or personal injury resulting from such
283 party’s negligence to the extent applicable law prohibits such limitation.
284 Some jurisdictions do not allow the exclusion or limitation of incidental or
285 consequential damages, so this exclusion and limitation may not apply to You.
286
2878. Litigation
288
289 Any litigation relating to this License may be brought only in the courts of
290 a jurisdiction where the defendant maintains its principal place of business
291 and such litigation shall be governed by laws of that jurisdiction, without
292 reference to its conflict-of-law provisions. Nothing in this Section shall
293 prevent a party’s ability to bring cross-claims or counter-claims.
294
2959. Miscellaneous
296
297 This License represents the complete agreement concerning the subject matter
298 hereof. If any provision of this License is held to be unenforceable, such
299 provision shall be reformed only to the extent necessary to make it
300 enforceable. Any law or regulation which provides that the language of a
301 contract shall be construed against the drafter shall not be used to construe
302 this License against a Contributor.
303
304
30510. Versions of the License
306
30710.1. New Versions
308
309 Mozilla Foundation is the license steward. Except as provided in Section
310 10.3, no one other than the license steward has the right to modify or
311 publish new versions of this License. Each version will be given a
312 distinguishing version number.
313
31410.2. Effect of New Versions
315
316 You may distribute the Covered Software under the terms of the version of
317 the License under which You originally received the Covered Software, or
318 under the terms of any subsequent version published by the license
319 steward.
320
32110.3. Modified Versions
322
323 If you create software not governed by this License, and you want to
324 create a new license for such software, you may create and use a modified
325 version of this License if you rename the license and remove any
326 references to the name of the license steward (except to note that such
327 modified license differs from this License).
328
32910.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
330 If You choose to distribute Source Code Form that is Incompatible With
331 Secondary Licenses under the terms of this version of the License, the
332 notice described in Exhibit B of this License must be attached.
333
334Exhibit A - Source Code Form License Notice
335
336 This Source Code Form is subject to the
337 terms of the Mozilla Public License, v.
338 2.0. If a copy of the MPL was not
339 distributed with this file, You can
340 obtain one at
341 http://mozilla.org/MPL/2.0/.
342
343If it is not possible or desirable to put the notice in a particular file, then
344You may include the notice in a location (such as a LICENSE file in a relevant
345directory) where a recipient would be likely to look for such a notice.
346
347You may add additional accurate notices of copyright ownership.
348
349Exhibit B - “Incompatible With Secondary Licenses” Notice
350
351 This Source Code Form is “Incompatible
352 With Secondary Licenses”, as defined by
353 the Mozilla Public License, v. 2.0.
354
diff --git a/vendor/github.com/hashicorp/go-version/README.md b/vendor/github.com/hashicorp/go-version/README.md
new file mode 100644
index 0000000..6f3a15c
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-version/README.md
@@ -0,0 +1,65 @@
1# Versioning Library for Go
2[![Build Status](https://travis-ci.org/hashicorp/go-version.svg?branch=master)](https://travis-ci.org/hashicorp/go-version)
3
4go-version is a library for parsing versions and version constraints,
5and verifying versions against a set of constraints. go-version
6can sort a collection of versions properly, handles prerelease/beta
7versions, can increment versions, etc.
8
9Versions used with go-version must follow [SemVer](http://semver.org/).
10
11## Installation and Usage
12
13Package documentation can be found on
14[GoDoc](http://godoc.org/github.com/hashicorp/go-version).
15
16Installation can be done with a normal `go get`:
17
18```
19$ go get github.com/hashicorp/go-version
20```
21
22#### Version Parsing and Comparison
23
24```go
25v1, err := version.NewVersion("1.2")
26v2, err := version.NewVersion("1.5+metadata")
27
28// Comparison example. There is also GreaterThan, Equal, and just
29// a simple Compare that returns an int allowing easy >=, <=, etc.
30if v1.LessThan(v2) {
31 fmt.Printf("%s is less than %s", v1, v2)
32}
33```
34
35#### Version Constraints
36
37```go
38v1, err := version.NewVersion("1.2")
39
40// Constraints example.
41constraints, err := version.NewConstraint(">= 1.0, < 1.4")
42if constraints.Check(v1) {
43 fmt.Printf("%s satisfies constraints %s", v1, constraints)
44}
45```
46
47#### Version Sorting
48
49```go
50versionsRaw := []string{"1.1", "0.7.1", "1.4-beta", "1.4", "2"}
51versions := make([]*version.Version, len(versionsRaw))
52for i, raw := range versionsRaw {
53 v, _ := version.NewVersion(raw)
54 versions[i] = v
55}
56
57// After this, the versions are properly sorted
58sort.Sort(version.Collection(versions))
59```
60
61## Issues and Contributing
62
63If you find an issue with this library, please report an issue. If you'd
64like, we welcome any contributions. Fork this library and submit a pull
65request.
diff --git a/vendor/github.com/hashicorp/go-version/constraint.go b/vendor/github.com/hashicorp/go-version/constraint.go
new file mode 100644
index 0000000..8c73df0
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-version/constraint.go
@@ -0,0 +1,178 @@
1package version
2
3import (
4 "fmt"
5 "regexp"
6 "strings"
7)
8
9// Constraint represents a single constraint for a version, such as
10// ">= 1.0".
11type Constraint struct {
12 f constraintFunc
13 check *Version
14 original string
15}
16
17// Constraints is a slice of constraints. We make a custom type so that
18// we can add methods to it.
19type Constraints []*Constraint
20
21type constraintFunc func(v, c *Version) bool
22
23var constraintOperators map[string]constraintFunc
24
25var constraintRegexp *regexp.Regexp
26
27func init() {
28 constraintOperators = map[string]constraintFunc{
29 "": constraintEqual,
30 "=": constraintEqual,
31 "!=": constraintNotEqual,
32 ">": constraintGreaterThan,
33 "<": constraintLessThan,
34 ">=": constraintGreaterThanEqual,
35 "<=": constraintLessThanEqual,
36 "~>": constraintPessimistic,
37 }
38
39 ops := make([]string, 0, len(constraintOperators))
40 for k := range constraintOperators {
41 ops = append(ops, regexp.QuoteMeta(k))
42 }
43
44 constraintRegexp = regexp.MustCompile(fmt.Sprintf(
45 `^\s*(%s)\s*(%s)\s*$`,
46 strings.Join(ops, "|"),
47 VersionRegexpRaw))
48}
49
50// NewConstraint will parse one or more constraints from the given
51// constraint string. The string must be a comma-separated list of
52// constraints.
53func NewConstraint(v string) (Constraints, error) {
54 vs := strings.Split(v, ",")
55 result := make([]*Constraint, len(vs))
56 for i, single := range vs {
57 c, err := parseSingle(single)
58 if err != nil {
59 return nil, err
60 }
61
62 result[i] = c
63 }
64
65 return Constraints(result), nil
66}
67
68// Check tests if a version satisfies all the constraints.
69func (cs Constraints) Check(v *Version) bool {
70 for _, c := range cs {
71 if !c.Check(v) {
72 return false
73 }
74 }
75
76 return true
77}
78
79// Returns the string format of the constraints
80func (cs Constraints) String() string {
81 csStr := make([]string, len(cs))
82 for i, c := range cs {
83 csStr[i] = c.String()
84 }
85
86 return strings.Join(csStr, ",")
87}
88
89// Check tests if a constraint is validated by the given version.
90func (c *Constraint) Check(v *Version) bool {
91 return c.f(v, c.check)
92}
93
94func (c *Constraint) String() string {
95 return c.original
96}
97
98func parseSingle(v string) (*Constraint, error) {
99 matches := constraintRegexp.FindStringSubmatch(v)
100 if matches == nil {
101 return nil, fmt.Errorf("Malformed constraint: %s", v)
102 }
103
104 check, err := NewVersion(matches[2])
105 if err != nil {
106 return nil, err
107 }
108
109 return &Constraint{
110 f: constraintOperators[matches[1]],
111 check: check,
112 original: v,
113 }, nil
114}
115
116//-------------------------------------------------------------------
117// Constraint functions
118//-------------------------------------------------------------------
119
120func constraintEqual(v, c *Version) bool {
121 return v.Equal(c)
122}
123
124func constraintNotEqual(v, c *Version) bool {
125 return !v.Equal(c)
126}
127
128func constraintGreaterThan(v, c *Version) bool {
129 return v.Compare(c) == 1
130}
131
132func constraintLessThan(v, c *Version) bool {
133 return v.Compare(c) == -1
134}
135
136func constraintGreaterThanEqual(v, c *Version) bool {
137 return v.Compare(c) >= 0
138}
139
140func constraintLessThanEqual(v, c *Version) bool {
141 return v.Compare(c) <= 0
142}
143
144func constraintPessimistic(v, c *Version) bool {
145 // 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
147 if v.LessThan(c) {
148 return false
149 }
150 // We'll use this more than once, so grab the length now so it's a little cleaner
151 // to write the later checks
152 cs := len(c.segments)
153
154 // If the version being checked has less specificity than the constraint, then there
155 // is no way for the version to be valid against the constraint
156 if cs > len(v.segments) {
157 return false
158 }
159
160 // Check the segments in the constraint against those in the version. If the version
161 // being checked, at any point, does not have the same values in each index of the
162 // constraints segments, then it cannot be valid against the constraint.
163 for i := 0; i < c.si-1; i++ {
164 if v.segments[i] != c.segments[i] {
165 return false
166 }
167 }
168
169 // Check the last part of the segment in the constraint. If the version segment at
170 // this index is less than the constraints segment at this index, then it cannot
171 // be valid against the constraint
172 if c.segments[cs-1] > v.segments[cs-1] {
173 return false
174 }
175
176 // If nothing has rejected the version by now, it's valid
177 return true
178}
diff --git a/vendor/github.com/hashicorp/go-version/version.go b/vendor/github.com/hashicorp/go-version/version.go
new file mode 100644
index 0000000..ae2f6b6
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-version/version.go
@@ -0,0 +1,308 @@
1package version
2
3import (
4 "bytes"
5 "fmt"
6 "reflect"
7 "regexp"
8 "strconv"
9 "strings"
10)
11
12// The compiled regular expression used to test the validity of a version.
13var versionRegexp *regexp.Regexp
14
15// The raw regular expression string used for testing the validity
16// of a version.
17const VersionRegexpRaw string = `v?([0-9]+(\.[0-9]+)*?)` +
18 `(-?([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` +
19 `(\+([0-9A-Za-z\-]+(\.[0-9A-Za-z\-]+)*))?` +
20 `?`
21
22// Version represents a single version.
23type Version struct {
24 metadata string
25 pre string
26 segments []int64
27 si int
28}
29
30func init() {
31 versionRegexp = regexp.MustCompile("^" + VersionRegexpRaw + "$")
32}
33
34// NewVersion parses the given version and returns a new
35// Version.
36func NewVersion(v string) (*Version, error) {
37 matches := versionRegexp.FindStringSubmatch(v)
38 if matches == nil {
39 return nil, fmt.Errorf("Malformed version: %s", v)
40 }
41 segmentsStr := strings.Split(matches[1], ".")
42 segments := make([]int64, len(segmentsStr))
43 si := 0
44 for i, str := range segmentsStr {
45 val, err := strconv.ParseInt(str, 10, 64)
46 if err != nil {
47 return nil, fmt.Errorf(
48 "Error parsing version: %s", err)
49 }
50
51 segments[i] = int64(val)
52 si++
53 }
54
55 // Even though we could support more than three segments, if we
56 // got less than three, pad it with 0s. This is to cover the basic
57 // default usecase of semver, which is MAJOR.MINOR.PATCH at the minimum
58 for i := len(segments); i < 3; i++ {
59 segments = append(segments, 0)
60 }
61
62 return &Version{
63 metadata: matches[7],
64 pre: matches[4],
65 segments: segments,
66 si: si,
67 }, nil
68}
69
70// Must is a helper that wraps a call to a function returning (*Version, error)
71// and panics if error is non-nil.
72func Must(v *Version, err error) *Version {
73 if err != nil {
74 panic(err)
75 }
76
77 return v
78}
79
80// Compare compares this version to another version. This
81// returns -1, 0, or 1 if this version is smaller, equal,
82// or larger than the other version, respectively.
83//
84// If you want boolean results, use the LessThan, Equal,
85// or GreaterThan methods.
86func (v *Version) Compare(other *Version) int {
87 // A quick, efficient equality check
88 if v.String() == other.String() {
89 return 0
90 }
91
92 segmentsSelf := v.Segments64()
93 segmentsOther := other.Segments64()
94
95 // If the segments are the same, we must compare on prerelease info
96 if reflect.DeepEqual(segmentsSelf, segmentsOther) {
97 preSelf := v.Prerelease()
98 preOther := other.Prerelease()
99 if preSelf == "" && preOther == "" {
100 return 0
101 }
102 if preSelf == "" {
103 return 1
104 }
105 if preOther == "" {
106 return -1
107 }
108
109 return comparePrereleases(preSelf, preOther)
110 }
111
112 // Get the highest specificity (hS), or if they're equal, just use segmentSelf length
113 lenSelf := len(segmentsSelf)
114 lenOther := len(segmentsOther)
115 hS := lenSelf
116 if lenSelf < lenOther {
117 hS = lenOther
118 }
119 // Compare the segments
120 // Because a constraint could have more/less specificity than the version it's
121 // checking, we need to account for a lopsided or jagged comparison
122 for i := 0; i < hS; i++ {
123 if i > lenSelf-1 {
124 // This means Self had the lower specificity
125 // Check to see if the remaining segments in Other are all zeros
126 if !allZero(segmentsOther[i:]) {
127 // if not, it means that Other has to be greater than Self
128 return -1
129 }
130 break
131 } else if i > lenOther-1 {
132 // this means Other had the lower specificity
133 // Check to see if the remaining segments in Self are all zeros -
134 if !allZero(segmentsSelf[i:]) {
135 //if not, it means that Self has to be greater than Other
136 return 1
137 }
138 break
139 }
140 lhs := segmentsSelf[i]
141 rhs := segmentsOther[i]
142 if lhs == rhs {
143 continue
144 } else if lhs < rhs {
145 return -1
146 }
147 // Otherwis, rhs was > lhs, they're not equal
148 return 1
149 }
150
151 // if we got this far, they're equal
152 return 0
153}
154
155func allZero(segs []int64) bool {
156 for _, s := range segs {
157 if s != 0 {
158 return false
159 }
160 }
161 return true
162}
163
164func comparePart(preSelf string, preOther string) int {
165 if preSelf == preOther {
166 return 0
167 }
168
169 // if a part is empty, we use the other to decide
170 if preSelf == "" {
171 _, notIsNumeric := strconv.ParseInt(preOther, 10, 64)
172 if notIsNumeric == nil {
173 return -1
174 }
175 return 1
176 }
177
178 if preOther == "" {
179 _, notIsNumeric := strconv.ParseInt(preSelf, 10, 64)
180 if notIsNumeric == nil {
181 return 1
182 }
183 return -1
184 }
185
186 if preSelf > preOther {
187 return 1
188 }
189
190 return -1
191}
192
193func comparePrereleases(v string, other string) int {
194 // the same pre release!
195 if v == other {
196 return 0
197 }
198
199 // split both pre releases for analyse their parts
200 selfPreReleaseMeta := strings.Split(v, ".")
201 otherPreReleaseMeta := strings.Split(other, ".")
202
203 selfPreReleaseLen := len(selfPreReleaseMeta)
204 otherPreReleaseLen := len(otherPreReleaseMeta)
205
206 biggestLen := otherPreReleaseLen
207 if selfPreReleaseLen > otherPreReleaseLen {
208 biggestLen = selfPreReleaseLen
209 }
210
211 // loop for parts to find the first difference
212 for i := 0; i < biggestLen; i = i + 1 {
213 partSelfPre := ""
214 if i < selfPreReleaseLen {
215 partSelfPre = selfPreReleaseMeta[i]
216 }
217
218 partOtherPre := ""
219 if i < otherPreReleaseLen {
220 partOtherPre = otherPreReleaseMeta[i]
221 }
222
223 compare := comparePart(partSelfPre, partOtherPre)
224 // if parts are equals, continue the loop
225 if compare != 0 {
226 return compare
227 }
228 }
229
230 return 0
231}
232
233// Equal tests if two versions are equal.
234func (v *Version) Equal(o *Version) bool {
235 return v.Compare(o) == 0
236}
237
238// GreaterThan tests if this version is greater than another version.
239func (v *Version) GreaterThan(o *Version) bool {
240 return v.Compare(o) > 0
241}
242
243// LessThan tests if this version is less than another version.
244func (v *Version) LessThan(o *Version) bool {
245 return v.Compare(o) < 0
246}
247
248// Metadata returns any metadata that was part of the version
249// string.
250//
251// Metadata is anything that comes after the "+" in the version.
252// For example, with "1.2.3+beta", the metadata is "beta".
253func (v *Version) Metadata() string {
254 return v.metadata
255}
256
257// Prerelease returns any prerelease data that is part of the version,
258// or blank if there is no prerelease data.
259//
260// Prerelease information is anything that comes after the "-" in the
261// version (but before any metadata). For example, with "1.2.3-beta",
262// the prerelease information is "beta".
263func (v *Version) Prerelease() string {
264 return v.pre
265}
266
267// Segments returns the numeric segments of the version as a slice of ints.
268//
269// This excludes any metadata or pre-release information. For example,
270// for a version "1.2.3-beta", segments will return a slice of
271// 1, 2, 3.
272func (v *Version) Segments() []int {
273 segmentSlice := make([]int, len(v.segments))
274 for i, v := range v.segments {
275 segmentSlice[i] = int(v)
276 }
277 return segmentSlice
278}
279
280// Segments64 returns the numeric segments of the version as a slice of int64s.
281//
282// This excludes any metadata or pre-release information. For example,
283// for a version "1.2.3-beta", segments will return a slice of
284// 1, 2, 3.
285func (v *Version) Segments64() []int64 {
286 return v.segments
287}
288
289// String returns the full version string included pre-release
290// and metadata information.
291func (v *Version) String() string {
292 var buf bytes.Buffer
293 fmtParts := make([]string, len(v.segments))
294 for i, s := range v.segments {
295 // We can ignore err here since we've pre-parsed the values in segments
296 str := strconv.FormatInt(s, 10)
297 fmtParts[i] = str
298 }
299 fmt.Fprintf(&buf, strings.Join(fmtParts, "."))
300 if v.pre != "" {
301 fmt.Fprintf(&buf, "-%s", v.pre)
302 }
303 if v.metadata != "" {
304 fmt.Fprintf(&buf, "+%s", v.metadata)
305 }
306
307 return buf.String()
308}
diff --git a/vendor/github.com/hashicorp/go-version/version_collection.go b/vendor/github.com/hashicorp/go-version/version_collection.go
new file mode 100644
index 0000000..cc888d4
--- /dev/null
+++ b/vendor/github.com/hashicorp/go-version/version_collection.go
@@ -0,0 +1,17 @@
1package version
2
3// Collection is a type that implements the sort.Interface interface
4// so that versions can be sorted.
5type Collection []*Version
6
7func (v Collection) Len() int {
8 return len(v)
9}
10
11func (v Collection) Less(i, j int) bool {
12 return v[i].LessThan(v[j])
13}
14
15func (v Collection) Swap(i, j int) {
16 v[i], v[j] = v[j], v[i]
17}