commands/plugin: Add "update" subcommand
This commit is contained in:
parent
c95a68ed5d
commit
ac1404b9ac
|
@ -17,6 +17,7 @@ BACKWARDS INCOMPATIBILITY:
|
|||
|
||||
FEATURES:
|
||||
|
||||
- New command: `vagrant plugin update` to update specific installed plugins.
|
||||
- Salt provisioner. [GH-1626]
|
||||
- Mac OS X guest support. [GH-1914]
|
||||
- CoreOS guest support. Change host names and configure networks on
|
||||
|
|
|
@ -411,6 +411,10 @@ module Vagrant
|
|||
error_key(:plugin_not_found)
|
||||
end
|
||||
|
||||
class PluginNotInstalled < VagrantError
|
||||
error_key(:plugin_not_installed)
|
||||
end
|
||||
|
||||
class SCPPermissionDenied < VagrantError
|
||||
error_key(:scp_permission_denied)
|
||||
end
|
||||
|
|
|
@ -39,12 +39,23 @@ module VagrantPlugins
|
|||
end
|
||||
end
|
||||
|
||||
# This middleware sequence will update a plugin.
|
||||
def self.action_update
|
||||
Vagrant::Action::Builder.new.tap do |b|
|
||||
b.use BundlerCheck
|
||||
b.use PluginExistsCheck
|
||||
b.use InstallGem
|
||||
b.use PruneGems
|
||||
end
|
||||
end
|
||||
|
||||
# The autoload farm
|
||||
action_root = Pathname.new(File.expand_path("../action", __FILE__))
|
||||
autoload :BundlerCheck, action_root.join("bundler_check")
|
||||
autoload :InstallGem, action_root.join("install_gem")
|
||||
autoload :LicensePlugin, action_root.join("license_plugin")
|
||||
autoload :ListPlugins, action_root.join("list_plugins")
|
||||
autoload :PluginExistsCheck, action_root.join("plugin_exists_check")
|
||||
autoload :PruneGems, action_root.join("prune_gems")
|
||||
autoload :UninstallPlugin, action_root.join("uninstall_plugin")
|
||||
end
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
require "set"
|
||||
|
||||
module VagrantPlugins
|
||||
module CommandPlugin
|
||||
module Action
|
||||
# This class checks to see if the plugin is installed already, and
|
||||
# if so, raises an exception/error to output to the user.
|
||||
class PluginExistsCheck
|
||||
def initialize(app, env)
|
||||
@app = app
|
||||
end
|
||||
|
||||
def call(env)
|
||||
# Get the list of installed plugins according to the state file
|
||||
installed = Set.new(env[:plugin_state_file].installed_plugins)
|
||||
if !installed.include?(env[:plugin_name])
|
||||
raise Vagrant::Errors::PluginNotInstalled,
|
||||
name: env[:plugin_name]
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,38 +1,21 @@
|
|||
require 'optparse'
|
||||
|
||||
require_relative "base"
|
||||
require_relative "mixin_install_opts"
|
||||
|
||||
module VagrantPlugins
|
||||
module CommandPlugin
|
||||
module Command
|
||||
class Install < Base
|
||||
include MixinInstallOpts
|
||||
|
||||
def execute
|
||||
options = {}
|
||||
|
||||
opts = OptionParser.new do |o|
|
||||
o.banner = "Usage: vagrant plugin install <name> [-h]"
|
||||
o.separator ""
|
||||
|
||||
o.on("--entry-point NAME", String,
|
||||
"The name of the entry point file for loading the plugin.") do |entry_point|
|
||||
options[:entry_point] = entry_point
|
||||
end
|
||||
|
||||
o.on("--plugin-prerelease",
|
||||
"Allow prerelease versions of this plugin.") do |plugin_prerelease|
|
||||
options[:plugin_prerelease] = plugin_prerelease
|
||||
end
|
||||
|
||||
o.on("--plugin-source PLUGIN_SOURCE", String,
|
||||
"Add a RubyGems repository source") do |plugin_source|
|
||||
options[:plugin_sources] ||= []
|
||||
options[:plugin_sources] << plugin_source
|
||||
end
|
||||
|
||||
o.on("--plugin-version PLUGIN_VERSION", String,
|
||||
"Install a specific version of the plugin") do |plugin_version|
|
||||
options[:plugin_version] = plugin_version
|
||||
end
|
||||
build_install_opts(o, options)
|
||||
end
|
||||
|
||||
# Parse the options
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
module VagrantPlugins
|
||||
module CommandPlugin
|
||||
module Command
|
||||
module MixinInstallOpts
|
||||
def build_install_opts(o, options)
|
||||
o.on("--entry-point NAME", String,
|
||||
"The name of the entry point file for loading the plugin.") do |entry_point|
|
||||
options[:entry_point] = entry_point
|
||||
end
|
||||
|
||||
o.on("--plugin-prerelease",
|
||||
"Allow prerelease versions of this plugin.") do |plugin_prerelease|
|
||||
options[:plugin_prerelease] = plugin_prerelease
|
||||
end
|
||||
|
||||
o.on("--plugin-source PLUGIN_SOURCE", String,
|
||||
"Add a RubyGems repository source") do |plugin_source|
|
||||
options[:plugin_sources] ||= []
|
||||
options[:plugin_sources] << plugin_source
|
||||
end
|
||||
|
||||
o.on("--plugin-version PLUGIN_VERSION", String,
|
||||
"Install a specific version of the plugin") do |plugin_version|
|
||||
options[:plugin_version] = plugin_version
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,6 +25,11 @@ module VagrantPlugins
|
|||
List
|
||||
end
|
||||
|
||||
@subcommands.register(:update) do
|
||||
require_relative "update"
|
||||
Update
|
||||
end
|
||||
|
||||
@subcommands.register(:uninstall) do
|
||||
require_relative "uninstall"
|
||||
Uninstall
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
require 'optparse'
|
||||
|
||||
require_relative "base"
|
||||
require_relative "mixin_install_opts"
|
||||
|
||||
module VagrantPlugins
|
||||
module CommandPlugin
|
||||
module Command
|
||||
class Update < Base
|
||||
include MixinInstallOpts
|
||||
|
||||
def execute
|
||||
options = {}
|
||||
|
||||
opts = OptionParser.new do |o|
|
||||
o.banner = "Usage: vagrant plugin update <name> [-h]"
|
||||
o.separator ""
|
||||
build_install_opts(o, options)
|
||||
end
|
||||
|
||||
# Parse the options
|
||||
argv = parse_options(opts)
|
||||
return if !argv
|
||||
raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
|
||||
|
||||
# Update the gem
|
||||
action(Action.action_update, {
|
||||
:plugin_entry_point => options[:entry_point],
|
||||
:plugin_prerelease => options[:plugin_prerelease],
|
||||
:plugin_version => options[:plugin_version],
|
||||
:plugin_sources => options[:plugin_sources],
|
||||
:plugin_name => argv[0]
|
||||
})
|
||||
|
||||
# Success, exit status 0
|
||||
0
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -417,6 +417,8 @@ en:
|
|||
plugin_not_found: |-
|
||||
The plugin '%{name}' could not be found. Please install this plugin
|
||||
prior to attempting to do anything with it.
|
||||
plugin_not_installed: |-
|
||||
The plugin '%{name}' is not installed. Please install it first.
|
||||
port_collision_resume: |-
|
||||
This VM cannot be resumed, because the forwarded ports would collide
|
||||
with a running program (it could be another virtual machine). Normally,
|
||||
|
|
Loading…
Reference in New Issue