vagrant/plugins/commands/version/command.rb

58 lines
1.5 KiB
Ruby
Raw Normal View History

2014-04-25 02:54:26 +00:00
require "optparse"
module VagrantPlugins
module CommandVersion
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"prints current and latest Vagrant version"
end
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant version"
end
# Parse the options
argv = parse_options(opts)
return if !argv
# Output the currently installed version instantly.
@env.ui.output(I18n.t(
"vagrant.version_current", version: Vagrant::VERSION))
@env.ui.machine("version-installed", Vagrant::VERSION)
2014-09-01 22:23:46 +00:00
# Load the latest information
cp = @env.checkpoint
if !cp
@env.ui.output("\n"+I18n.t(
"vagrant.version_no_checkpoint"))
return 0
end
latest = cp["current_version"]
2014-04-25 02:54:26 +00:00
# Output latest version
@env.ui.output(I18n.t(
2014-04-25 03:09:32 +00:00
"vagrant.version_latest", version: latest))
@env.ui.machine("version-latest", latest)
2014-04-25 02:54:26 +00:00
# Determine if its a new version, and if so, output some more
# information.
current = Gem::Version.new(Vagrant::VERSION)
2014-04-25 03:09:32 +00:00
latest = Gem::Version.new(latest)
2014-04-25 02:54:26 +00:00
if current >= latest
@env.ui.success(" \n" + I18n.t(
"vagrant.version_latest_installed"))
return 0
end
# Out of date! Let the user know how to upgrade.
@env.ui.output(" \n" + I18n.t(
"vagrant.version_upgrade_howto", version: latest.to_s))
0
end
end
end
end