commands/plugin: convert all actions to use the new classes
This commit is contained in:
parent
8904319beb
commit
5fe2994005
|
@ -63,7 +63,7 @@ module Vagrant
|
|||
|
||||
# This returns the list of plugins that should be enabled.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
# @return [Hash]
|
||||
def installed_plugins
|
||||
@global_file.installed_plugins
|
||||
end
|
||||
|
|
|
@ -15,6 +15,7 @@ module VagrantPlugins
|
|||
# This middleware sequence licenses paid addons.
|
||||
def self.action_license
|
||||
Vagrant::Action::Builder.new.tap do |b|
|
||||
b.use PluginExistsCheck
|
||||
b.use LicensePlugin
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,15 +17,6 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def call(env)
|
||||
# Get the list of installed plugins according to the state file
|
||||
installed = env[:plugin_state_file].installed_plugins.keys
|
||||
|
||||
# If the plugin we're trying to license doesn't exist in the
|
||||
# state file, then it is an error.
|
||||
if !installed.include?(env[:plugin_name])
|
||||
raise Vagrant::Errors::PluginNotFound, :name => env[:plugin_name]
|
||||
end
|
||||
|
||||
# Verify the license file exists
|
||||
license_file = Pathname.new(env[:plugin_license_path])
|
||||
if !license_file.file?
|
||||
|
|
|
@ -16,31 +16,15 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def call(env)
|
||||
# Get the list of installed plugins according to the state file
|
||||
installed = env[:plugin_state_file].installed_plugins.keys
|
||||
|
||||
# Go through the plugins installed in this environment and
|
||||
# get the latest version of each.
|
||||
installed_map = {}
|
||||
Vagrant::Plugin::Manager.instance.installed_specs.each do |spec|
|
||||
# Ignore specs that aren't in our installed list
|
||||
next if !installed.include?(spec.name)
|
||||
|
||||
# If we already have a newer version in our list of installed,
|
||||
# then ignore it
|
||||
next if installed_map.has_key?(spec.name) &&
|
||||
installed_map[spec.name].version >= spec.version
|
||||
|
||||
installed_map[spec.name] = spec
|
||||
end
|
||||
specs = Vagrant::Plugin::Manager.instance.installed_specs
|
||||
|
||||
# Output!
|
||||
if installed_map.empty?
|
||||
if specs.empty?
|
||||
env[:ui].info(I18n.t("vagrant.commands.plugin.no_plugins"))
|
||||
else
|
||||
installed_map.values.each do |spec|
|
||||
env[:ui].info "#{spec.name} (#{spec.version})"
|
||||
end
|
||||
end
|
||||
|
||||
specs.each do |spec|
|
||||
env[:ui].info "#{spec.name} (#{spec.version})"
|
||||
end
|
||||
|
||||
@app.call(env)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
require "set"
|
||||
require "vagrant/plugin/manager"
|
||||
|
||||
module VagrantPlugins
|
||||
module CommandPlugin
|
||||
|
@ -11,9 +11,8 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def call(env)
|
||||
# Get the list of installed plugins according to the state file
|
||||
installed = env[:plugin_state_file].installed_plugins.keys
|
||||
if !installed.include?(env[:plugin_name])
|
||||
installed = Vagrant::Plugin::Manager.instance.installed_specs
|
||||
if !installed.has_key?(env[:plugin_name])
|
||||
raise Vagrant::Errors::PluginNotInstalled,
|
||||
name: env[:plugin_name]
|
||||
end
|
||||
|
|
|
@ -11,11 +11,6 @@ module VagrantPlugins
|
|||
# @param [Object] callable the Middleware callable
|
||||
# @param [Hash] env Extra environment hash that is merged in.
|
||||
def action(callable, env=nil)
|
||||
env = {
|
||||
:gem_helper => GemHelper.new(@env.gems_path),
|
||||
:plugin_state_file => Vagrant::Plugin::StateFile.new(@env.home_path.join("plugins.json"))
|
||||
}.merge(env || {})
|
||||
|
||||
@env.action_runner.run(callable, env)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -16,6 +16,5 @@ DESC
|
|||
end
|
||||
|
||||
autoload :Action, File.expand_path("../action", __FILE__)
|
||||
autoload :GemHelper, File.expand_path("../gem_helper", __FILE__)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue