├── .gitignore ├── Godeps ├── Godeps.json ├── Readme └── _workspace │ ├── .gitignore │ └── src │ └── github.com │ └── hashicorp │ └── go-version │ ├── .travis.yml │ ├── LICENSE │ ├── README.md │ ├── constraint.go │ ├── constraint_test.go │ ├── version.go │ ├── version_collection.go │ ├── version_collection_test.go │ └── version_test.go ├── LICENSE.md ├── README.md └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | -------------------------------------------------------------------------------- /Godeps/Godeps.json: -------------------------------------------------------------------------------- 1 | { 2 | "ImportPath": "github.com/roots/roots-cli", 3 | "GoVersion": "go1.4.2", 4 | "Packages": [ 5 | "." 6 | ], 7 | "Deps": [ 8 | { 9 | "ImportPath": "github.com/hashicorp/go-version", 10 | "Rev": "2b9865f60ce11e527bd1255ba82036d465570aa3" 11 | } 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /Godeps/Readme: -------------------------------------------------------------------------------- 1 | This directory tree is generated automatically by godep. 2 | 3 | Please do not edit. 4 | 5 | See https://github.com/tools/godep for more information. 6 | -------------------------------------------------------------------------------- /Godeps/_workspace/.gitignore: -------------------------------------------------------------------------------- 1 | /pkg 2 | /bin 3 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.0 5 | - 1.1 6 | - 1.2 7 | - 1.3 8 | - 1.4 9 | 10 | script: 11 | - go test 12 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License, version 2.0 2 | 3 | 1. Definitions 4 | 5 | 1.1. “Contributor” 6 | 7 | means each individual or legal entity that creates, contributes to the 8 | creation of, or owns Covered Software. 9 | 10 | 1.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 | 15 | 1.3. “Contribution” 16 | 17 | means Covered Software of a particular Contributor. 18 | 19 | 1.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 | 26 | 1.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 | 36 | 1.6. “Executable Form” 37 | 38 | means any form of the work other than Source Code Form. 39 | 40 | 1.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 | 45 | 1.8. “License” 46 | 47 | means this document. 48 | 49 | 1.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 | 55 | 1.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 | 64 | 1.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 | 72 | 1.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 | 78 | 1.13. “Source Code Form” 79 | 80 | means the form of the work preferred for making modifications. 81 | 82 | 1.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 | 93 | 2. License Grants and Conditions 94 | 95 | 2.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 | 110 | 2.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 | 116 | 2.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 | 137 | 2.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 | 144 | 2.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 | 150 | 2.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 | 155 | 2.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 | 161 | 3. Responsibilities 162 | 163 | 3.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 | 172 | 3.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 | 187 | 3.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 | 199 | 3.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 | 207 | 3.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 | 220 | 4. 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 | 232 | 5. Termination 233 | 234 | 5.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 | 247 | 5.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 | 254 | 5.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 | 259 | 6. 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 | 272 | 7. 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 | 287 | 8. 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 | 295 | 9. 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 | 305 | 10. Versions of the License 306 | 307 | 10.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 | 314 | 10.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 | 321 | 10.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 | 329 | 10.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 | 334 | Exhibit 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 | 343 | If it is not possible or desirable to put the notice in a particular file, then 344 | You may include the notice in a location (such as a LICENSE file in a relevant 345 | directory) where a recipient would be likely to look for such a notice. 346 | 347 | You may add additional accurate notices of copyright ownership. 348 | 349 | Exhibit 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 | 355 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/README.md: -------------------------------------------------------------------------------- 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 | 4 | go-version is a library for parsing versions and version constraints, 5 | and verifying versions against a set of constraints. go-version 6 | can sort a collection of versions properly, handles prerelease/beta 7 | versions, can increment versions, etc. 8 | 9 | Versions used with go-version must follow [SemVer](http://semver.org/). 10 | 11 | ## Installation and Usage 12 | 13 | Package documentation can be found on 14 | [GoDoc](http://godoc.org/github.com/hashicorp/go-version). 15 | 16 | Installation 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 25 | v1, err := version.NewVersion("1.2") 26 | v2, 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. 30 | if v1.LessThan(v2) { 31 | fmt.Printf("%s is less than %s", v1, v2) 32 | } 33 | ``` 34 | 35 | #### Version Constraints 36 | 37 | ```go 38 | v1, err := version.NewVersion("1.2") 39 | 40 | // Constraints example. 41 | constraints, err := version.NewConstraint(">= 1.0, < 1.4") 42 | if constraints.Check(v1) { 43 | fmt.Printf("%s satisfies constraints %s", v1, constraints) 44 | } 45 | ``` 46 | 47 | #### Version Sorting 48 | 49 | ```go 50 | versionsRaw := []string{"1.1", "0.7.1", "1.4-beta", "1.4", "2"} 51 | versions := make([]*version.Version, len(versionsRaw)) 52 | for i, raw := range versionsRaw { 53 | v, _ := version.NewVersion(raw) 54 | versions[i] = v 55 | } 56 | 57 | // After this, the versions are properly sorted 58 | sort.Sort(version.Collection(versions)) 59 | ``` 60 | 61 | ## Issues and Contributing 62 | 63 | If you find an issue with this library, please report an issue. If you'd 64 | like, we welcome any contributions. Fork this library and submit a pull 65 | request. 66 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/constraint.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "fmt" 5 | "regexp" 6 | "strings" 7 | ) 8 | 9 | // Constraint represents a single constraint for a version, such as 10 | // ">= 1.0". 11 | type 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. 19 | type Constraints []*Constraint 20 | 21 | type constraintFunc func(v, c *Version) bool 22 | 23 | var constraintOperators map[string]constraintFunc 24 | 25 | var constraintRegexp *regexp.Regexp 26 | 27 | func 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. 53 | func 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. 69 | func (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 80 | func (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. 90 | func (c *Constraint) Check(v *Version) bool { 91 | return c.f(v, c.check) 92 | } 93 | 94 | func (c *Constraint) String() string { 95 | return c.original 96 | } 97 | 98 | func 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 | // This is a panic because the regular expression above should 107 | // properly validate any version. 108 | panic(err) 109 | } 110 | 111 | return &Constraint{ 112 | f: constraintOperators[matches[1]], 113 | check: check, 114 | original: v, 115 | }, nil 116 | } 117 | 118 | //------------------------------------------------------------------- 119 | // Constraint functions 120 | //------------------------------------------------------------------- 121 | 122 | func constraintEqual(v, c *Version) bool { 123 | return v.Equal(c) 124 | } 125 | 126 | func constraintNotEqual(v, c *Version) bool { 127 | return !v.Equal(c) 128 | } 129 | 130 | func constraintGreaterThan(v, c *Version) bool { 131 | return v.Compare(c) == 1 132 | } 133 | 134 | func constraintLessThan(v, c *Version) bool { 135 | return v.Compare(c) == -1 136 | } 137 | 138 | func constraintGreaterThanEqual(v, c *Version) bool { 139 | return v.Compare(c) >= 0 140 | } 141 | 142 | func constraintLessThanEqual(v, c *Version) bool { 143 | return v.Compare(c) <= 0 144 | } 145 | 146 | func constraintPessimistic(v, c *Version) bool { 147 | if v.LessThan(c) { 148 | return false 149 | } 150 | 151 | for i := 0; i < c.si-1; i++ { 152 | if v.segments[i] != c.segments[i] { 153 | return false 154 | } 155 | } 156 | 157 | return true 158 | } 159 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/constraint_test.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestNewConstraint(t *testing.T) { 8 | cases := []struct { 9 | input string 10 | count int 11 | err bool 12 | }{ 13 | {">= 1.2", 1, false}, 14 | {"1.0", 1, false}, 15 | {">= 1.x", 0, true}, 16 | {">= 1.2, < 1.0", 2, false}, 17 | } 18 | 19 | for _, tc := range cases { 20 | v, err := NewConstraint(tc.input) 21 | if tc.err && err == nil { 22 | t.Fatalf("expected error for input: %s", tc.input) 23 | } else if !tc.err && err != nil { 24 | t.Fatalf("error for input %s: %s", tc.input, err) 25 | } 26 | 27 | if len(v) != tc.count { 28 | t.Fatalf("input: %s\nexpected len: %d\nactual: %d", 29 | tc.input, tc.count, len(v)) 30 | } 31 | } 32 | } 33 | 34 | func TestConstraintCheck(t *testing.T) { 35 | cases := []struct { 36 | constraint string 37 | version string 38 | check bool 39 | }{ 40 | {">= 1.0, < 1.2", "1.1.5", true}, 41 | {"< 1.0, < 1.2", "1.1.5", false}, 42 | {"= 1.0", "1.1.5", false}, 43 | {"= 1.0", "1.0.0", true}, 44 | {"1.0", "1.0.0", true}, 45 | {"~> 1.0", "2.0", false}, 46 | {"~> 1.0", "1.1", true}, 47 | {"~> 1.0", "1.2.3", true}, 48 | {"~> 1.0.0", "1.2.3", false}, 49 | {"~> 1.0.0", "1.0.7", true}, 50 | {"~> 1.0.0", "1.1.0", false}, 51 | {"~> 1.0.7", "1.0.4", false}, 52 | } 53 | 54 | for _, tc := range cases { 55 | c, err := NewConstraint(tc.constraint) 56 | if err != nil { 57 | t.Fatalf("err: %s", err) 58 | } 59 | 60 | v, err := NewVersion(tc.version) 61 | if err != nil { 62 | t.Fatalf("err: %s", err) 63 | } 64 | 65 | actual := c.Check(v) 66 | expected := tc.check 67 | if actual != expected { 68 | t.Fatalf("Version: %s\nConstraint: %s\nExpected: %#v", 69 | tc.version, tc.constraint, expected) 70 | } 71 | } 72 | } 73 | 74 | func TestConstraintsString(t *testing.T) { 75 | cases := []struct { 76 | constraint string 77 | result string 78 | }{ 79 | {">= 1.0, < 1.2", ""}, 80 | {"~> 1.0.7", ""}, 81 | } 82 | 83 | for _, tc := range cases { 84 | c, err := NewConstraint(tc.constraint) 85 | if err != nil { 86 | t.Fatalf("err: %s", err) 87 | } 88 | 89 | actual := c.String() 90 | expected := tc.result 91 | if expected == "" { 92 | expected = tc.constraint 93 | } 94 | 95 | if actual != expected { 96 | t.Fatalf("Constraint: %s\nExpected: %#v\nActual: %s", 97 | tc.constraint, expected, actual) 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/version.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 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. 13 | var versionRegexp *regexp.Regexp 14 | 15 | // The raw regular expression string used for testing the validity 16 | // of a version. 17 | const VersionRegexpRaw string = `([0-9]+(\.[0-9]+){0,2})` + 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. 23 | type Version struct { 24 | metadata string 25 | pre string 26 | segments []int 27 | si int 28 | } 29 | 30 | func init() { 31 | versionRegexp = regexp.MustCompile("^" + VersionRegexpRaw + "$") 32 | } 33 | 34 | // NewVersion parses the given version and returns a new 35 | // Version. 36 | func 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 | 42 | segmentsStr := strings.Split(matches[1], ".") 43 | segments := make([]int, len(segmentsStr), 3) 44 | si := 0 45 | for i, str := range segmentsStr { 46 | val, err := strconv.ParseInt(str, 10, 32) 47 | if err != nil { 48 | return nil, fmt.Errorf( 49 | "Error parsing version: %s", err) 50 | } 51 | 52 | segments[i] = int(val) 53 | si += 1 54 | } 55 | for i := len(segments); i < 3; i++ { 56 | segments = append(segments, 0) 57 | } 58 | 59 | return &Version{ 60 | metadata: matches[7], 61 | pre: matches[4], 62 | segments: segments, 63 | si: si, 64 | }, nil 65 | } 66 | 67 | // Must is a helper that wraps a call to a function returning (*Version, error) 68 | // and panics if error is non-nil. 69 | func Must(v *Version, err error) *Version { 70 | if err != nil { 71 | panic(err) 72 | } 73 | 74 | return v 75 | } 76 | 77 | // Compare compares this version to another version. This 78 | // returns -1, 0, or 1 if this version is smaller, equal, 79 | // or larger than the other version, respectively. 80 | // 81 | // If you want boolean results, use the LessThan, Equal, 82 | // or GreaterThan methods. 83 | func (v *Version) Compare(other *Version) int { 84 | // A quick, efficient equality check 85 | if v.String() == other.String() { 86 | return 0 87 | } 88 | 89 | segmentsSelf := v.Segments() 90 | segmentsOther := other.Segments() 91 | 92 | // If the segments are the same, we must compare on prerelease info 93 | if reflect.DeepEqual(segmentsSelf, segmentsOther) { 94 | preSelf := v.Prerelease() 95 | preOther := other.Prerelease() 96 | if preSelf == "" && preOther == "" { 97 | return 0 98 | } 99 | if preSelf == "" { 100 | return 1 101 | } 102 | if preOther == "" { 103 | return -1 104 | } 105 | 106 | return comparePrereleases(preSelf, preOther) 107 | } 108 | 109 | // Compare the segments 110 | for i := 0; i < len(segmentsSelf); i++ { 111 | lhs := segmentsSelf[i] 112 | rhs := segmentsOther[i] 113 | 114 | if lhs == rhs { 115 | continue 116 | } else if lhs < rhs { 117 | return -1 118 | } else { 119 | return 1 120 | } 121 | } 122 | 123 | panic("should not be reached") 124 | } 125 | 126 | func comparePart(preSelf string, preOther string) int { 127 | if preSelf == preOther { 128 | return 0 129 | } 130 | 131 | // if a part is empty, we use the other to decide 132 | if preSelf == "" { 133 | _, notIsNumeric := strconv.ParseInt(preOther, 10, 64) 134 | if notIsNumeric == nil { 135 | return -1 136 | } 137 | return 1 138 | } 139 | 140 | if preOther == "" { 141 | _, notIsNumeric := strconv.ParseInt(preSelf, 10, 64) 142 | if notIsNumeric == nil { 143 | return 1 144 | } 145 | return -1 146 | } 147 | 148 | if preSelf > preOther { 149 | return 1 150 | } 151 | 152 | return -1 153 | } 154 | 155 | func comparePrereleases(v string, other string) int { 156 | // the same pre release! 157 | if v == other { 158 | return 0 159 | } 160 | 161 | // split both pre releases for analyse their parts 162 | selfPreReleaseMeta := strings.Split(v, ".") 163 | otherPreReleaseMeta := strings.Split(other, ".") 164 | 165 | selfPreReleaseLen := len(selfPreReleaseMeta) 166 | otherPreReleaseLen := len(otherPreReleaseMeta) 167 | 168 | biggestLen := otherPreReleaseLen 169 | if selfPreReleaseLen > otherPreReleaseLen { 170 | biggestLen = selfPreReleaseLen 171 | } 172 | 173 | // loop for parts to find the first difference 174 | for i := 0; i < biggestLen; i = i + 1 { 175 | partSelfPre := "" 176 | if i < selfPreReleaseLen { 177 | partSelfPre = selfPreReleaseMeta[i] 178 | } 179 | 180 | partOtherPre := "" 181 | if i < otherPreReleaseLen { 182 | partOtherPre = otherPreReleaseMeta[i] 183 | } 184 | 185 | compare := comparePart(partSelfPre, partOtherPre) 186 | // if parts are equals, continue the loop 187 | if compare != 0 { 188 | return compare 189 | } 190 | } 191 | 192 | return 0 193 | } 194 | 195 | // Equal tests if two versions are equal. 196 | func (v *Version) Equal(o *Version) bool { 197 | return v.Compare(o) == 0 198 | } 199 | 200 | // GreaterThan tests if this version is greater than another version. 201 | func (v *Version) GreaterThan(o *Version) bool { 202 | return v.Compare(o) > 0 203 | } 204 | 205 | // LessThan tests if this version is less than another version. 206 | func (v *Version) LessThan(o *Version) bool { 207 | return v.Compare(o) < 0 208 | } 209 | 210 | // Metadata returns any metadata that was part of the version 211 | // string. 212 | // 213 | // Metadata is anything that comes after the "+" in the version. 214 | // For example, with "1.2.3+beta", the metadata is "beta". 215 | func (v *Version) Metadata() string { 216 | return v.metadata 217 | } 218 | 219 | // Prerelease returns any prerelease data that is part of the version, 220 | // or blank if there is no prerelease data. 221 | // 222 | // Prerelease information is anything that comes after the "-" in the 223 | // version (but before any metadata). For example, with "1.2.3-beta", 224 | // the prerelease information is "beta". 225 | func (v *Version) Prerelease() string { 226 | return v.pre 227 | } 228 | 229 | // Segments returns the numeric segments of the version as a slice. 230 | // 231 | // This excludes any metadata or pre-release information. For example, 232 | // for a version "1.2.3-beta", segments will return a slice of 233 | // 1, 2, 3. 234 | func (v *Version) Segments() []int { 235 | return v.segments 236 | } 237 | 238 | // String returns the full version string included pre-release 239 | // and metadata information. 240 | func (v *Version) String() string { 241 | var buf bytes.Buffer 242 | fmt.Fprintf(&buf, "%d.%d.%d", v.segments[0], v.segments[1], v.segments[2]) 243 | if v.pre != "" { 244 | fmt.Fprintf(&buf, "-%s", v.pre) 245 | } 246 | if v.metadata != "" { 247 | fmt.Fprintf(&buf, "+%s", v.metadata) 248 | } 249 | 250 | return buf.String() 251 | } 252 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/version_collection.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | // Collection is a type that implements the sort.Interface interface 4 | // so that versions can be sorted. 5 | type Collection []*Version 6 | 7 | func (v Collection) Len() int { 8 | return len(v) 9 | } 10 | 11 | func (v Collection) Less(i, j int) bool { 12 | return v[i].LessThan(v[j]) 13 | } 14 | 15 | func (v Collection) Swap(i, j int) { 16 | v[i], v[j] = v[j], v[i] 17 | } 18 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/version_collection_test.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "reflect" 5 | "sort" 6 | "testing" 7 | ) 8 | 9 | func TestCollection(t *testing.T) { 10 | versionsRaw := []string{ 11 | "1.1.1", 12 | "1.0", 13 | "1.2", 14 | "2", 15 | "0.7.1", 16 | } 17 | 18 | versions := make([]*Version, len(versionsRaw)) 19 | for i, raw := range versionsRaw { 20 | v, err := NewVersion(raw) 21 | if err != nil { 22 | t.Fatalf("err: %s", err) 23 | } 24 | 25 | versions[i] = v 26 | } 27 | 28 | sort.Sort(Collection(versions)) 29 | 30 | actual := make([]string, len(versions)) 31 | for i, v := range versions { 32 | actual[i] = v.String() 33 | } 34 | 35 | expected := []string{ 36 | "0.7.1", 37 | "1.0.0", 38 | "1.1.1", 39 | "1.2.0", 40 | "2.0.0", 41 | } 42 | 43 | if !reflect.DeepEqual(actual, expected) { 44 | t.Fatalf("bad: %#v", actual) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Godeps/_workspace/src/github.com/hashicorp/go-version/version_test.go: -------------------------------------------------------------------------------- 1 | package version 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func TestNewVersion(t *testing.T) { 9 | cases := []struct { 10 | version string 11 | err bool 12 | }{ 13 | {"1.2.3", false}, 14 | {"1.0", false}, 15 | {"1", false}, 16 | {"1.2.beta", true}, 17 | {"foo", true}, 18 | {"1.2-5", false}, 19 | {"1.2-beta.5", false}, 20 | {"\n1.2", true}, 21 | {"1.2.0-x.Y.0+metadata", false}, 22 | {"1.2.0-x.Y.0+metadata-width-hypen", false}, 23 | {"1.2.3-rc1-with-hypen", false}, 24 | {"1.2.3.4", true}, 25 | } 26 | 27 | for _, tc := range cases { 28 | _, err := NewVersion(tc.version) 29 | if tc.err && err == nil { 30 | t.Fatalf("expected error for version: %s", tc.version) 31 | } else if !tc.err && err != nil { 32 | t.Fatalf("error for version %s: %s", tc.version, err) 33 | } 34 | } 35 | } 36 | 37 | func TestVersionCompare(t *testing.T) { 38 | cases := []struct { 39 | v1 string 40 | v2 string 41 | expected int 42 | }{ 43 | {"1.2.3", "1.4.5", -1}, 44 | {"1.2-beta", "1.2-beta", 0}, 45 | {"1.2", "1.1.4", 1}, 46 | {"1.2", "1.2-beta", 1}, 47 | {"1.2+foo", "1.2+beta", 0}, 48 | } 49 | 50 | for _, tc := range cases { 51 | v1, err := NewVersion(tc.v1) 52 | if err != nil { 53 | t.Fatalf("err: %s", err) 54 | } 55 | 56 | v2, err := NewVersion(tc.v2) 57 | if err != nil { 58 | t.Fatalf("err: %s", err) 59 | } 60 | 61 | actual := v1.Compare(v2) 62 | expected := tc.expected 63 | if actual != expected { 64 | t.Fatalf( 65 | "%s <=> %s\nexpected: %d\nactual: %d", 66 | tc.v1, tc.v2, 67 | expected, actual) 68 | } 69 | } 70 | } 71 | 72 | func TestComparePreReleases(t *testing.T) { 73 | cases := []struct { 74 | v1 string 75 | v2 string 76 | expected int 77 | }{ 78 | {"1.2-beta.2", "1.2-beta.2", 0}, 79 | {"1.2-beta.1", "1.2-beta.2", -1}, 80 | {"3.2-alpha.1", "3.2-alpha", 1}, 81 | {"1.2-beta.2", "1.2-beta.1", 1}, 82 | {"1.2-beta", "1.2-beta.3", -1}, 83 | {"1.2-alpha", "1.2-beta.3", -1}, 84 | {"1.2-beta", "1.2-alpha.3", 1}, 85 | {"3.0-alpha.3", "3.0-rc.1", -1}, 86 | {"3.0-alpha3", "3.0-rc1", -1}, 87 | {"3.0-alpha.1", "3.0-alpha.beta", -1}, 88 | {"5.4-alpha", "5.4-alpha.beta", 1}, 89 | } 90 | 91 | for _, tc := range cases { 92 | v1, err := NewVersion(tc.v1) 93 | if err != nil { 94 | t.Fatalf("err: %s", err) 95 | } 96 | 97 | v2, err := NewVersion(tc.v2) 98 | if err != nil { 99 | t.Fatalf("err: %s", err) 100 | } 101 | 102 | actual := v1.Compare(v2) 103 | expected := tc.expected 104 | if actual != expected { 105 | t.Fatalf( 106 | "%s <=> %s\nexpected: %d\nactual: %d", 107 | tc.v1, tc.v2, 108 | expected, actual) 109 | } 110 | } 111 | } 112 | 113 | func TestVersionMetadata(t *testing.T) { 114 | cases := []struct { 115 | version string 116 | expected string 117 | }{ 118 | {"1.2.3", ""}, 119 | {"1.2-beta", ""}, 120 | {"1.2.0-x.Y.0", ""}, 121 | {"1.2.0-x.Y.0+metadata", "metadata"}, 122 | } 123 | 124 | for _, tc := range cases { 125 | v, err := NewVersion(tc.version) 126 | if err != nil { 127 | t.Fatalf("err: %s", err) 128 | } 129 | 130 | actual := v.Metadata() 131 | expected := tc.expected 132 | if actual != expected { 133 | t.Fatalf("expected: %s\nactual: %s", expected, actual) 134 | } 135 | } 136 | } 137 | 138 | func TestVersionPrerelease(t *testing.T) { 139 | cases := []struct { 140 | version string 141 | expected string 142 | }{ 143 | {"1.2.3", ""}, 144 | {"1.2-beta", "beta"}, 145 | {"1.2.0-x.Y.0", "x.Y.0"}, 146 | {"1.2.0-x.Y.0+metadata", "x.Y.0"}, 147 | } 148 | 149 | for _, tc := range cases { 150 | v, err := NewVersion(tc.version) 151 | if err != nil { 152 | t.Fatalf("err: %s", err) 153 | } 154 | 155 | actual := v.Prerelease() 156 | expected := tc.expected 157 | if actual != expected { 158 | t.Fatalf("expected: %s\nactual: %s", expected, actual) 159 | } 160 | } 161 | } 162 | 163 | func TestVersionSegments(t *testing.T) { 164 | cases := []struct { 165 | version string 166 | expected []int 167 | }{ 168 | {"1.2.3", []int{1, 2, 3}}, 169 | {"1.2-beta", []int{1, 2, 0}}, 170 | {"1-x.Y.0", []int{1, 0, 0}}, 171 | {"1.2.0-x.Y.0+metadata", []int{1, 2, 0}}, 172 | } 173 | 174 | for _, tc := range cases { 175 | v, err := NewVersion(tc.version) 176 | if err != nil { 177 | t.Fatalf("err: %s", err) 178 | } 179 | 180 | actual := v.Segments() 181 | expected := tc.expected 182 | if !reflect.DeepEqual(actual, expected) { 183 | t.Fatalf("expected: %#v\nactual: %#v", expected, actual) 184 | } 185 | } 186 | } 187 | 188 | func TestVersionString(t *testing.T) { 189 | cases := [][]string{ 190 | {"1.2.3", "1.2.3"}, 191 | {"1.2-beta", "1.2.0-beta"}, 192 | {"1.2.0-x.Y.0", "1.2.0-x.Y.0"}, 193 | {"1.2.0-x.Y.0+metadata", "1.2.0-x.Y.0+metadata"}, 194 | } 195 | 196 | for _, tc := range cases { 197 | v, err := NewVersion(tc[0]) 198 | if err != nil { 199 | t.Fatalf("err: %s", err) 200 | } 201 | 202 | actual := v.String() 203 | expected := tc[1] 204 | if actual != expected { 205 | t.Fatalf("expected: %s\nactual: %s", expected, actual) 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Roots 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # roots-cli 2 | 3 | Start a brand new Roots project with one command. 4 | 5 | **Warning: This project is pre-alpha** 6 | 7 | The base implementation will serve the following requirements: 8 | 9 | - Generate a Sage theme starting point 10 | - Generate a Bedrock scaffold 11 | - Generate a Trellis install 12 | - Generate a project with all of the above 13 | 14 | After this base implementation is accomplished, we can examine more features that will benefit other parts of a project lifecycle. See [Issue #1](https://github.com/roots/roots-cli/issues/1) 15 | 16 | ## Current phase: scaffold a basic Trellis project 17 | 18 | See [Issue #2](https://github.com/roots/roots-cli/issues/2) 19 | 20 | ## Questions and feedback 21 | 22 | Please use the [roots-cli category on Roots Discourse](https://discourse.roots.io/c/roots-cli) instead of using GitHub issues. 23 | 24 | ## Installation 25 | 26 | ### Compile from source 27 | 28 | ``` 29 | go get github.com/roots/roots-cli 30 | ``` 31 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "github.com/roots/roots-cli/Godeps/_workspace/src/github.com/hashicorp/go-version" 6 | "os" 7 | "os/exec" 8 | "path/filepath" 9 | "strings" 10 | ) 11 | 12 | func check(err error) { 13 | if err != nil { 14 | panic(err) 15 | } 16 | } 17 | 18 | func checkMsg(err error, msg string) { 19 | if err != nil { 20 | fmt.Println(msg) 21 | panic(err) 22 | } 23 | } 24 | 25 | func checkTrellisRequirements() { 26 | ansiblePlaybook, err := exec.LookPath("ansible-playbook") 27 | checkMsg(err, "You need ansible-playbook") 28 | ansibleVersionCommand := exec.Command(ansiblePlaybook, "--version") 29 | ansibleVersionOutput, err := ansibleVersionCommand.Output() 30 | versionText := string(ansibleVersionOutput) 31 | versionArray := strings.Split(versionText, "\n") 32 | userVersion, err := version.NewVersion(strings.Split(versionArray[0], " ")[1]) 33 | check(err) 34 | 35 | acceptableVersions := ">= 1.9.2, < 2.0.0" 36 | constraint, err := version.NewConstraint(acceptableVersions) 37 | check(err) 38 | 39 | if !constraint.Check(userVersion) { 40 | fmt.Println("Invalid version of ansible. We require " + acceptableVersions) 41 | os.Exit(1) 42 | } 43 | } 44 | 45 | func cloneRepo(repo string, location string) { 46 | git, err := exec.LookPath("git") 47 | check(err) 48 | 49 | gitCommand := exec.Command( 50 | git, 51 | "clone", 52 | "https://github.com/roots/"+repo, 53 | location, 54 | ) 55 | gitCommand.Stderr = os.Stdout 56 | gitCommand.Run() 57 | } 58 | 59 | func scaffoldProject(args []string) { 60 | target, err := filepath.Abs(args[0]) 61 | check(err) 62 | checkTrellisRequirements() 63 | cloneRepo("trellis", target) 64 | fmt.Println(target) 65 | } 66 | 67 | func main() { 68 | fmt.Println("hello") 69 | args := os.Args[1:] 70 | 71 | command := args[0] 72 | 73 | if command == "new" { 74 | scaffoldProject(args[1:]) 75 | } 76 | } 77 | --------------------------------------------------------------------------------