Created
November 13, 2013 13:31
-
-
Save petems/7449151 to your computer and use it in GitHub Desktop.
Check Vagrant version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MIN_REQUIRED_VAGRANT_VERSION = '1.2.1' | |
if Vagrant::VERSION < MIN_REQUIRED_VAGRANT_VERSION | |
$stderr.puts "ERROR: We require Vagrant version >=#{min_required_vagrant_version}. Please upgrade. http://downloads.vagrantup.com/\n" | |
exit 1 | |
end | |
Vagrant.configure("2") do |config| | |
config.vm.box = "precise64" | |
config.vm.hostname = 'foo' | |
config.vm.box_url = "http://files.vagrantup.com/precise64.box" | |
end |
Yeah, this is pretty old at this point (2013?), I think this pre-dates the Vagrant.version?
method:
I later found that version comparisons in Ruby are fairly simple to do with the Gem library as well:
Gem::Version.new(Vagrant::VERSION) < Gem::Version.new(MIN_REQUIRED_VAGRANT_VERSION)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Although this is probably years old at this point, it should be noted that this version check appears to do lexicographical comparison. For example, this results in
2.2.10
being handled as if it were an earlier version than2.2.6
(for example).I don't know when this was added (or if it was always there), but Vagrant now has their own function for checking the version: