commands/version: check latest version
This commit is contained in:
parent
466f77beaf
commit
63dffe3f92
|
@ -0,0 +1,60 @@
|
||||||
|
require "json"
|
||||||
|
require "optparse"
|
||||||
|
require "tempfile"
|
||||||
|
|
||||||
|
require "vagrant/util/downloader"
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
# Load the latest installed version to output that.
|
||||||
|
tf = Tempfile.new("vagrant")
|
||||||
|
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
|
||||||
|
@env.ui.output(I18n.t(
|
||||||
|
"vagrant.version_latest", version: data["version"]))
|
||||||
|
@env.ui.machine("version-latest", data["version"])
|
||||||
|
|
||||||
|
# Determine if its a new version, and if so, output some more
|
||||||
|
# information.
|
||||||
|
current = Gem::Version.new(Vagrant::VERSION)
|
||||||
|
latest = Gem::Version.new(data["version"])
|
||||||
|
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
|
|
@ -0,0 +1,18 @@
|
||||||
|
require "vagrant"
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module CommandVersion
|
||||||
|
class Plugin < Vagrant.plugin("2")
|
||||||
|
name "version command"
|
||||||
|
description <<-DESC
|
||||||
|
The `version` command prints the currently installed version
|
||||||
|
as well as the latest available version.
|
||||||
|
DESC
|
||||||
|
|
||||||
|
command("version") do
|
||||||
|
require File.expand_path("../command", __FILE__)
|
||||||
|
Command
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -223,6 +223,23 @@ en:
|
||||||
up some disk space.
|
up some disk space.
|
||||||
|
|
||||||
Press any other key to continue.
|
Press any other key to continue.
|
||||||
|
version_current: |-
|
||||||
|
Installed Version: %{version}
|
||||||
|
version_latest: |-
|
||||||
|
Latest Version: %{version}
|
||||||
|
version_latest_installed: |-
|
||||||
|
You're running an up-to-date version of Vagrant!
|
||||||
|
version_upgrade_howto: |-
|
||||||
|
To upgrade to the latest version, visit the downloads page and
|
||||||
|
download and install the latest version of Vagrant from the URL
|
||||||
|
below:
|
||||||
|
|
||||||
|
http://www.vagrantup.com/downloads.html
|
||||||
|
|
||||||
|
If you're curious what changed in the latest release, view the
|
||||||
|
CHANGELOG below:
|
||||||
|
|
||||||
|
https://github.com/mitchellh/vagrant/blob/v%{version}/CHANGELOG.md
|
||||||
cfengine_config:
|
cfengine_config:
|
||||||
classes_array: |-
|
classes_array: |-
|
||||||
The 'classes' configuration must be an array.
|
The 'classes' configuration must be an array.
|
||||||
|
|
|
@ -123,6 +123,7 @@
|
||||||
<li<%= sidebar_current("cli-status") %>><a href="/v2/cli/status.html">status</a></li>
|
<li<%= sidebar_current("cli-status") %>><a href="/v2/cli/status.html">status</a></li>
|
||||||
<li<%= sidebar_current("cli-suspend") %>><a href="/v2/cli/suspend.html">suspend</a></li>
|
<li<%= sidebar_current("cli-suspend") %>><a href="/v2/cli/suspend.html">suspend</a></li>
|
||||||
<li<%= sidebar_current("cli-up") %>><a href="/v2/cli/up.html">up</a></li>
|
<li<%= sidebar_current("cli-up") %>><a href="/v2/cli/up.html">up</a></li>
|
||||||
|
<li<%= sidebar_current("cli-version") %>><a href="/v2/cli/version.html">version</a></li>
|
||||||
<li<%= sidebar_current("cli-nonprimary") %>><a href="/v2/cli/non-primary.html">More Commands</a></li>
|
<li<%= sidebar_current("cli-nonprimary") %>><a href="/v2/cli/non-primary.html">More Commands</a></li>
|
||||||
<li<%= sidebar_current("cli-machinereadable") %>><a href="/v2/cli/machine-readable.html">Machine Readable Output</a></li>
|
<li<%= sidebar_current("cli-machinereadable") %>><a href="/v2/cli/machine-readable.html">Machine Readable Output</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
page_title: "vagrant version - Command-Line Interface"
|
||||||
|
sidebar_current: "cli-version"
|
||||||
|
---
|
||||||
|
|
||||||
|
# Version
|
||||||
|
|
||||||
|
**Command: `vagrant version`**
|
||||||
|
|
||||||
|
This command tells you the version of Vagrant you have installed
|
||||||
|
as well as the latest version of Vagrant that is currently available.
|
||||||
|
|
||||||
|
In order to determine the latest available Vagrant version, this
|
||||||
|
command must make a network call. If you only want to see the currently
|
||||||
|
installed version, use `vagrant --version`.
|
Loading…
Reference in New Issue