Add local plugin repair support. Update global repair implementation.

This commit is contained in:
Chris Roberts 2018-07-18 13:46:17 -07:00
parent ef0269c538
commit 3fd55dac23
2 changed files with 36 additions and 3 deletions

View File

@ -19,11 +19,13 @@ module VagrantPlugins
def call(env)
env[:ui].info(I18n.t("vagrant.commands.plugin.repairing"))
plugins = Vagrant::Plugin::Manager.instance.installed_plugins
plugins = Vagrant::Plugin::Manager.instance.globalize!
begin
ENV["VAGRANT_DISABLE_PLUGIN_INIT"] = nil
Vagrant::Bundler.instance.init!(plugins, :repair)
ENV["VAGRANT_DISABLE_PLUGIN_INIT"] = "1"
env[:ui].info(I18n.t("vagrant.commands.plugin.repair_complete"))
rescue Exception => e
rescue => e
@logger.error("Failed to repair user installed plugins: #{e.class} - #{e}")
e.backtrace.each do |backtrace_line|
@logger.debug(backtrace_line)
@ -34,6 +36,27 @@ module VagrantPlugins
@app.call(env)
end
end
class RepairPluginsLocal
def initialize(app, env)
@app = app
@logger = Log4r::Logger.new("vagrant::plugins::plugincommand::repair_local")
end
def call(env)
Vagrant::Plugin::Manager.instance.localize!(env[:env]).each_pair do |pname, pinfo|
env[:env].action_runner.run(Action.action_install,
plugin_name: pname,
plugin_entry_point: pinfo["require"],
plugin_sources: pinfo["sources"],
plugin_version: pinfo["gem_version"],
plugin_env_local: true
)
end
# Continue
@app.call(env)
end
end
end
end
end

View File

@ -7,8 +7,14 @@ module VagrantPlugins
module Command
class Repair < Base
def execute
options = {}
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant plugin repair [-h]"
o.on("--local", "Install plugin for local project only") do |l|
options[:env_local] = l
end
end
# Parse the options
@ -16,8 +22,12 @@ module VagrantPlugins
return if !argv
raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp if argv.length > 0
if options[:env_local]
action(Action.action_repair_local, env: @env)
end
# Attempt to repair installed plugins
action(Action.action_repair)
action(Action.action_repair, options)
# Success, exit status 0
0