core: add Vagrant.latest_version
This commit is contained in:
parent
63dffe3f92
commit
6870de3f6d
|
@ -1,4 +1,5 @@
|
||||||
require "pathname"
|
require "pathname"
|
||||||
|
require "tempfile"
|
||||||
|
|
||||||
module Vagrant
|
module Vagrant
|
||||||
# This is the default endpoint of the Vagrant Cloud in
|
# This is the default endpoint of the Vagrant Cloud in
|
||||||
|
@ -25,6 +26,23 @@ module Vagrant
|
||||||
ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
|
ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns the latest version of Vagrant that is available.
|
||||||
|
#
|
||||||
|
# This makes an HTTP call.
|
||||||
|
#
|
||||||
|
# @return [String]
|
||||||
|
def self.latest_version
|
||||||
|
# Lazy-require this so that the overhead of this file is low
|
||||||
|
require "vagrant/util/downloader"
|
||||||
|
|
||||||
|
tf = Tempfile.new("vagrant")
|
||||||
|
tf.close
|
||||||
|
url = "http://www.vagrantup.com/latest-version.json"
|
||||||
|
Vagrant::Util::Downloader.new(url, tf.path).download!
|
||||||
|
data = JSON.parse(File.read(tf.path))
|
||||||
|
data["version"]
|
||||||
|
end
|
||||||
|
|
||||||
# This returns whether or not 3rd party plugins should be loaded.
|
# This returns whether or not 3rd party plugins should be loaded.
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
require "json"
|
require "json"
|
||||||
require "optparse"
|
require "optparse"
|
||||||
require "tempfile"
|
|
||||||
|
|
||||||
require "vagrant/util/downloader"
|
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module CommandVersion
|
module CommandVersion
|
||||||
|
@ -25,24 +22,18 @@ module VagrantPlugins
|
||||||
"vagrant.version_current", version: Vagrant::VERSION))
|
"vagrant.version_current", version: Vagrant::VERSION))
|
||||||
@env.ui.machine("version-installed", Vagrant::VERSION)
|
@env.ui.machine("version-installed", Vagrant::VERSION)
|
||||||
|
|
||||||
# Load the latest installed version to output that.
|
# Load the latest version
|
||||||
tf = Tempfile.new("vagrant")
|
latest = Vagrant.latest_version
|
||||||
tf.close
|
|
||||||
url = "http://www.vagrantup.com/latest-version.json"
|
|
||||||
Vagrant::Util::Downloader.new(url, tf.path).download!
|
|
||||||
|
|
||||||
# Parse the JSON result
|
|
||||||
data = JSON.parse(File.read(tf.path))
|
|
||||||
|
|
||||||
# Output latest version
|
# Output latest version
|
||||||
@env.ui.output(I18n.t(
|
@env.ui.output(I18n.t(
|
||||||
"vagrant.version_latest", version: data["version"]))
|
"vagrant.version_latest", version: latest))
|
||||||
@env.ui.machine("version-latest", data["version"])
|
@env.ui.machine("version-latest", latest)
|
||||||
|
|
||||||
# Determine if its a new version, and if so, output some more
|
# Determine if its a new version, and if so, output some more
|
||||||
# information.
|
# information.
|
||||||
current = Gem::Version.new(Vagrant::VERSION)
|
current = Gem::Version.new(Vagrant::VERSION)
|
||||||
latest = Gem::Version.new(data["version"])
|
latest = Gem::Version.new(latest)
|
||||||
if current >= latest
|
if current >= latest
|
||||||
@env.ui.success(" \n" + I18n.t(
|
@env.ui.success(" \n" + I18n.t(
|
||||||
"vagrant.version_latest_installed"))
|
"vagrant.version_latest_installed"))
|
||||||
|
|
Loading…
Reference in New Issue