vagrant-wrapper 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 `sha1(OWNER) = df334a7237f10846a0ca302bd323e35ee1463931`
2
+  
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+  
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+  
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,223 @@
1
+ # Vagrant Wrapper Gem
2
+
3
+ A gem providing access and bundling to the newer packaged versions of Vagrant. (I.E. Vagrant 1.1+)
4
+
5
+ - Allow your projects to depend on newer versions of Vagrant.
6
+ - Ensure shell calls are routed to the packaged version (even if the older Gem version is installed).
7
+ - Easily check and enforce version requirements.
8
+
9
+ **Please note:** this Gem does not install any version of Vagrant, it provides a compatibility layer over the newer packaged version. However, functions are included which may be used to guide the installation of Vagrant, when necessary.
10
+
11
+ **[More information on why this Gem exists can be seen in the Background section below.](#background---aka-the-vagrant-gem-enigma)**
12
+
13
+
14
+ # Installation and Usage
15
+
16
+ Require the Vagrant Wrapper via your Gemfile, then run `bundle install`.
17
+
18
+ source 'https://rubygems.org'
19
+
20
+ gem 'vagrant-wrapper'
21
+
22
+ Shell calls to 'vagrant' in your project will now always use the packaged version of Vagrant if available,
23
+ even if the now deprecated Vagrant Gem is installed and available in your Rubygems path.
24
+
25
+ Existing projects which require the old 'vagrant' gem in their Gemfile directly will continue to see
26
+ and use the older Gem version, even if they are shelling out as well.
27
+
28
+ **Please note:** The wrapper searches for a packaged installation of Vagrant first, and then falls back to any version it can find in the PATH. Therefore it will link to the 1.0.x gem version if that's all that is installed, so you should always enforce a minimum Vagrant version, see below.
29
+
30
+
31
+ ## Gemfile examples
32
+
33
+ **Let's assume you have both Vagrant 1.0.7 installed via a Gem, and Vagrant 1.2 installed via the official package.**
34
+
35
+ ### A... Older 'vagrant' gemfiles
36
+
37
+ This older Gemfile will still launch Vagrant 1.0.7, as expected:
38
+
39
+ **Gemfile**
40
+
41
+ source 'https://rubygems.org'
42
+ gem 'vagrant'
43
+
44
+ **Output**
45
+
46
+ puts %x{vagrant -v}
47
+ => "Vagrant version 1.0.7"
48
+
49
+ _Notes below on [VAGRANT_HOME](#vagrant_home) with older versions._
50
+
51
+ ### B... Simply Leaving out 'vagrant'
52
+
53
+ This is the key problem the Vagrant Wrapper seeks to solve, because otherwise (without uninstalling the vagrant gem), your shell calls will still be routed to 1.0.7.
54
+
55
+ **Gemfile**
56
+
57
+ source 'https://rubygems.org'
58
+
59
+ **Output**
60
+
61
+ puts %x{vagrant -v}
62
+ => "Vagrant version 1.0.7"
63
+
64
+ ### C... Including 'vagrant-wrapper'
65
+
66
+ Calls to vagrant now route to the newer packaged version.
67
+
68
+ **Gemfile**
69
+
70
+ source 'https://rubygems.org'
71
+ gem 'vagrant-wrapper'
72
+
73
+ **Output**
74
+
75
+ puts %x{vagrant -v}
76
+ => "Vagrant version 1.2.0"
77
+
78
+
79
+ ## Shell interaction
80
+
81
+ By requiring 'vagrant-wrapper' in your Gemfile, all calls to vagrant (inside and outside of Ruby), will use the packaged Vagrant install if available.
82
+
83
+ Simply call `vagrant` via a Ruby back tick, or from the command line.
84
+
85
+
86
+ ### Requiring a specific version (shell out)
87
+
88
+ If Vagrant is missing (or older than a version you specify) the command will return a standard-error message:
89
+
90
+ Vagrant >= 1.1 is required. You have 1.0.7.
91
+ See http://www.vagrantup.com for instructions.
92
+
93
+ Ruby
94
+
95
+ %x{vagrant --min-ver=1.1 box list}
96
+
97
+ Bash
98
+
99
+ bundle exec vagrant --min-ver=1.1 box list
100
+
101
+
102
+ ## Ruby interaction
103
+
104
+ Ruby functions exist for even deeper integration. For full documentation, please see the [RDoc](http://rubydoc.info/gems/vagrant-wrapper).
105
+
106
+ ### Requiring a specific version (Ruby)
107
+
108
+ ```ruby
109
+ require 'vagrant-wrapper'
110
+
111
+ # Will throw VagrantWrapper::Exceptions::Version
112
+ vw = VagrantWrapper.new(">= 1.1")
113
+
114
+ # This does the same thing:
115
+ vw = VagrantWrapper.new
116
+ vw.require_version(">= 1.1.")
117
+ ```
118
+
119
+ ### Handle a missing version
120
+
121
+ ```ruby
122
+ # You could handle the error like this:
123
+ begin
124
+ vw = VagrantWrapper.new(">= 1.1")
125
+ rescue VagrantWrapper::Exceptions::Version => e
126
+ $stderr.print e.message + "\n"
127
+ $stderr.print vw.install_instructions
128
+ exit(1)
129
+ end
130
+
131
+ # Which is the same as:
132
+ VagrantWrapper.require_or_help_install(">= 1.1")
133
+ ```
134
+
135
+ ### Getting the current version
136
+
137
+ ```ruby
138
+ require 'vagrant-wrapper'
139
+ VagrantWrapper.new.vagrant_version
140
+ # => "1.1.5" (nil if not installed)
141
+ ```
142
+
143
+ ### Getting the output of a call to vagrant
144
+
145
+ ```ruby
146
+ require 'vagrant-wrapper'
147
+ box_list = VagrantWrapper.new.get_output "box list"
148
+ ```
149
+
150
+ ### Handing process control to vagrant
151
+
152
+ This will cause vagrant to become the main process, as if you'd called it on the command-line. Execution will not return to your Ruby script.
153
+
154
+ ```ruby
155
+ require 'vagrant-wrapper'
156
+ VagrantWrapper.new.execute "up"
157
+ puts "This line would never be printed."
158
+ ```
159
+
160
+
161
+ ## Versioning
162
+
163
+ Please note, the version of this wrapper does not indicate (or mandate) any specific version of Vagrant
164
+ on the target system. As above, use the VagrantWrapper API for managing the vagrant version.
165
+
166
+ It's okay if the 'vagrant-wrapper' gem's version does not match the desired version of Vagrant. Therefore specifying a version of the wrapper in your Gemfile is not recommended.
167
+
168
+ ### VAGRANT_HOME
169
+
170
+ Major differences in Vagrant will refuse to use the same existing shared data directory. If you have an older project requiring the 'vagrant' gem that's fine, but you may need to set the VAGRANT_HOME environment variable to point to another location.
171
+
172
+ $ export VAGRANT_HOME=~/.vagrant.old
173
+
174
+ ----------
175
+
176
+ # Background - AKA the Vagrant Gem enigma
177
+
178
+ Per the creator's discretion, Vagrant 1.1+ no longer ships in Gem form,
179
+ [see here](https://groups.google.com/d/msg/vagrant-up/kX_wvn7wcds/luwNur4kgDEJ),
180
+ in favor of packaged installers.
181
+
182
+ There are many ways in which this is a strong move for the project, and in theory Vagrant's ability to use
183
+ its own bundled Ruby allows it to operate in a vacuum. So why does this wrapper exist?
184
+
185
+ The problem is that Gems do (and will always) exist for the older versions. If they are installed they tend
186
+ to override the system installed version of Vagrant if shell calls are made from within Ruby projects.
187
+
188
+ As an example, if you have any bundled project that requires the 'vagrant' gem via its Gemfile, and a newer
189
+ project that does not require this Gem (hoping to rely on the system packaged version), you'll find that
190
+ the Gem version of Vagrant will always be called when your program attempts to access Vagrant via a shell
191
+ or subprocess.
192
+
193
+ This is because the Rubygems bin directory is higher in your PATH, and using "bundle exec" will not help.
194
+ Even though Bundler will attempt to broker between multiple versions of Gems, it cannot handle the choice
195
+ between the Gem version and the system version.
196
+
197
+ Your only option would be to remove the old vagrant gem between projects, which is cumbersome. Also the problem will recur if you run a "bundle install" on a project which still includes the older Gem. This wrapper
198
+ solves the problem by giving your newer projects something to include and override the older Gem versions
199
+ of Vagrant.
200
+
201
+ ----------
202
+
203
+ # Development and Maintenance
204
+
205
+ * Found a bug?
206
+ * Need some help?
207
+ * Have a suggestion?
208
+ * Want to contribute?
209
+
210
+ Please visit: [code.binbab.org](http://code.binbab.org)
211
+
212
+
213
+ ## Integration Testing
214
+
215
+ bundle install
216
+ rake test
217
+
218
+
219
+ # Authors and License
220
+
221
+ * Author:: BinaryBabel OSS (<projects@binarybabel.org>)
222
+ * Copyright:: 2013 `sha1(OWNER) = df334a7237f10846a0ca302bd323e35ee1463931`
223
+ * License:: MIT
data/bin/vagrant CHANGED
@@ -1,7 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'vagrant-wrapper'
4
- #require_relative '../lib/vagrant-wrapper.rb'
5
- VagrantWrapper.new.execute(ARGV)
4
+
5
+ min_ver = nil
6
+
7
+ if (i = ARGV.index { |x| x =~ /^--min-ver=/ })
8
+ min_ver = ARGV.delete_at(i).split('=')[1]
9
+ end
10
+
11
+ unless min_ver
12
+ VagrantWrapper.new.execute(ARGV)
13
+ else
14
+ VagrantWrapper.require_or_help_install(">= #{min_ver}").execute(ARGV)
15
+ end
6
16
 
7
17
  # END VAGRANT WRAPPER
@@ -0,0 +1,6 @@
1
+ class VagrantWrapper
2
+ class Exceptions
3
+ class Version < RuntimeError ; end
4
+ class NotInstalled < Version ; end
5
+ end
6
+ end
@@ -1,3 +1,18 @@
1
+ #
2
+ # Author:: BinaryBabel OSS (<projects@binarybabel.org>)
3
+ # Homepage:: http://www.binarybabel.org
4
+ # License:: MIT
5
+ #
6
+ # For bugs, docs, updates:
7
+ #
8
+ # http://code.binbab.org
9
+ #
10
+ # Copyright 2013 sha1(OWNER) = df334a7237f10846a0ca302bd323e35ee1463931
11
+ #
12
+ # See LICENSE file for more details.
13
+ #
14
+
15
+ require 'vagrant-wrapper/exceptions'
1
16
  require 'Shellwords'
2
17
 
3
18
  # Main class for the VagrantWrapper driver.
@@ -7,16 +22,26 @@ require 'Shellwords'
7
22
  # if the vagrant-wrapper Gem is required in your bundle.
8
23
  class VagrantWrapper
9
24
 
10
- def initialize
25
+ def initialize(*args)
11
26
  @vagrant_name = "vagrant"
12
27
  @vagrant_path = nil
13
- @search_paths = default_paths
28
+ @search_paths = default_paths + env_paths
14
29
  @wrapper_mark = "END VAGRANT WRAPPER"
15
30
 
16
- # Include environment paths as low priority searches.
17
- env_path = ENV['PATH'].to_s
18
- if "" != env_path
19
- @search_paths.concat(env_path.split(':'))
31
+ # Optional first parameter sets required version.
32
+ unless args.length < 1 or args[0].nil?
33
+ require_version args[0]
34
+ end
35
+ end
36
+
37
+ # Require a specific version (or range of versions).
38
+ # Ex. ">= 1.1"
39
+ def require_version(version)
40
+ version_req = Gem::Requirement.new(version)
41
+ vagrant_ver = vagrant_version
42
+ raise Exceptions::NotInstalled, "Vagrant is not installed." if vagrant_ver.nil?
43
+ unless version_req.satisfied_by?(Gem::Version.new(vagrant_ver))
44
+ raise Exceptions::Version, "Vagrant #{version} is required. You have #{vagrant_ver}."
20
45
  end
21
46
  end
22
47
 
@@ -24,18 +49,18 @@ class VagrantWrapper
24
49
  # The given arguments (if any) are passed along to the command line.
25
50
  #
26
51
  # The output will be returned.
27
- def execute(*args)
52
+ def get_output(*args)
28
53
  if args.length > 0 && args[0].is_a?(Array)
29
- send("exec_vagrant", *args[0])
54
+ send("call_vagrant", *args[0])
30
55
  else
31
- send("exec_vagrant", *args)
56
+ send("call_vagrant", *args)
32
57
  end
33
58
  end
34
59
 
35
60
  # Execute the discovered version of Vagrant.
36
61
  # The given arguments (if any) are passed along to the command line.
37
62
  #
38
- # The vagrant process will replace this processe entirely, operating
63
+ # The vagrant process will replace this process entirely, operating
39
64
  # and outputting in an unmodified state.
40
65
  def execute(*args)
41
66
  if args.length > 0 && args[0].is_a?(Array)
@@ -50,7 +75,7 @@ class VagrantWrapper
50
75
  find_vagrant
51
76
  end
52
77
 
53
- # Return the version of the discovered Vagrent install.
78
+ # Return the version of the discovered Vagrant install.
54
79
  def vagrant_version
55
80
  ver = call_vagrant "-v"
56
81
  unless ver.nil?
@@ -73,8 +98,32 @@ class VagrantWrapper
73
98
  }
74
99
  end
75
100
 
101
+ # Environment search paths to be used as low priority search.
102
+ def env_paths
103
+ path = ENV['PATH'].to_s.strip
104
+ return [] if path.empty?
105
+ path.split(':')
106
+ end
107
+
108
+ def self.install_instructions
109
+ "See http://www.vagrantup.com for instructions.\n"
110
+ end
111
+
112
+ def self.require_or_help_install(version)
113
+ begin
114
+ vw = VagrantWrapper.new(version)
115
+ rescue Exceptions::Version => e
116
+ $stderr.print e.message + "\n"
117
+ $stderr.print install_instructions
118
+ exit(1)
119
+ end
120
+ vw
121
+ end
122
+
76
123
  protected
77
124
 
125
+ attr_accessor :search_paths
126
+
78
127
  # Locate the installed version of Vagrant using the provided paths.
79
128
  # Exclude the wrapper itself, should it be discovered by the search.
80
129
  def find_vagrant
@@ -96,14 +145,14 @@ class VagrantWrapper
96
145
  return nil
97
146
  end
98
147
  args.unshift(vagrant)
99
- %x{#{Shellwords.join(args)} + ' 2>&1'}
148
+ %x{#{Shellwords.join(args)} 2>&1}
100
149
  end
101
150
 
102
151
  # Give execution control to Vagrant.
103
152
  def exec_vagrant(*args)
104
153
  unless vagrant = find_vagrant
105
- $stderr.puts "Vagrant does not appear to be installed."
106
- $stderr.puts "See http://www.vagrantup.com for instructions."
154
+ $stderr.puts "Vagrant is not installed."
155
+ $stderr.print install_instructions
107
156
  exit(1)
108
157
  end
109
158
  args.unshift(vagrant)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,20 +9,49 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-18 00:00:00.000000000 Z
13
- dependencies: []
14
- description: ! 'Given Vagrant 1.1+ is distributed only via packaged installers, this
15
- Gem provides
12
+ date: 2013-05-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: vagrant
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - '='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.0.7
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.0.7
46
+ description: ! 'Since Vagrant 1.1+ is no longer distributed via Gems, vagrant-wrapper
47
+ allows you to require and interact
16
48
 
17
- a wrapper such-that an existing Gem install of the older Vagrant will not take
49
+ with the newer package versions via your Gemfile, shell, or Ruby code. It allows
50
+ the newer packaged
18
51
 
19
- precedence on the command line in a bundled project. Eg. shell calls to ''vagrant''
52
+ version to take precedence even if the older Vagrant gem remains installed.
20
53
 
21
- will use the packaged version.
22
-
23
-
24
- (NOTE: The version of the Gem does not determine the version of Vagrant it links
25
- to.)
54
+ See https://github.com/org-binbab/gem-vagrant-wrapper for more details.
26
55
 
27
56
  '
28
57
  email:
@@ -32,6 +61,9 @@ executables:
32
61
  extensions: []
33
62
  extra_rdoc_files: []
34
63
  files:
64
+ - LICENSE
65
+ - README.md
66
+ - lib/vagrant-wrapper/exceptions.rb
35
67
  - lib/vagrant-wrapper.rb
36
68
  - bin/vagrant
37
69
  homepage: http://code.binbab.org