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.
|
# This returns the list of plugins that should be enabled.
|
||||||
#
|
#
|
||||||
# @return [Array<String>]
|
# @return [Hash]
|
||||||
def installed_plugins
|
def installed_plugins
|
||||||
@global_file.installed_plugins
|
@global_file.installed_plugins
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,7 @@ module VagrantPlugins
|
||||||
# This middleware sequence licenses paid addons.
|
# This middleware sequence licenses paid addons.
|
||||||
def self.action_license
|
def self.action_license
|
||||||
Vagrant::Action::Builder.new.tap do |b|
|
Vagrant::Action::Builder.new.tap do |b|
|
||||||
|
b.use PluginExistsCheck
|
||||||
b.use LicensePlugin
|
b.use LicensePlugin
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,15 +17,6 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
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
|
# Verify the license file exists
|
||||||
license_file = Pathname.new(env[:plugin_license_path])
|
license_file = Pathname.new(env[:plugin_license_path])
|
||||||
if !license_file.file?
|
if !license_file.file?
|
||||||
|
|
|
@ -16,31 +16,15 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
# Get the list of installed plugins according to the state file
|
specs = Vagrant::Plugin::Manager.instance.installed_specs
|
||||||
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
|
|
||||||
|
|
||||||
# Output!
|
# Output!
|
||||||
if installed_map.empty?
|
if specs.empty?
|
||||||
env[:ui].info(I18n.t("vagrant.commands.plugin.no_plugins"))
|
env[:ui].info(I18n.t("vagrant.commands.plugin.no_plugins"))
|
||||||
else
|
end
|
||||||
installed_map.values.each do |spec|
|
|
||||||
env[:ui].info "#{spec.name} (#{spec.version})"
|
specs.each do |spec|
|
||||||
end
|
env[:ui].info "#{spec.name} (#{spec.version})"
|
||||||
end
|
end
|
||||||
|
|
||||||
@app.call(env)
|
@app.call(env)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require "set"
|
require "vagrant/plugin/manager"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module CommandPlugin
|
module CommandPlugin
|
||||||
|
@ -11,9 +11,8 @@ module VagrantPlugins
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
# Get the list of installed plugins according to the state file
|
installed = Vagrant::Plugin::Manager.instance.installed_specs
|
||||||
installed = env[:plugin_state_file].installed_plugins.keys
|
if !installed.has_key?(env[:plugin_name])
|
||||||
if !installed.include?(env[:plugin_name])
|
|
||||||
raise Vagrant::Errors::PluginNotInstalled,
|
raise Vagrant::Errors::PluginNotInstalled,
|
||||||
name: env[:plugin_name]
|
name: env[:plugin_name]
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,11 +11,6 @@ module VagrantPlugins
|
||||||
# @param [Object] callable the Middleware callable
|
# @param [Object] callable the Middleware callable
|
||||||
# @param [Hash] env Extra environment hash that is merged in.
|
# @param [Hash] env Extra environment hash that is merged in.
|
||||||
def action(callable, env=nil)
|
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)
|
@env.action_runner.run(callable, env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,5 @@ DESC
|
||||||
end
|
end
|
||||||
|
|
||||||
autoload :Action, File.expand_path("../action", __FILE__)
|
autoload :Action, File.expand_path("../action", __FILE__)
|
||||||
autoload :GemHelper, File.expand_path("../gem_helper", __FILE__)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue