From 3fd55dac23a6b22fb4d13f23bb9b7e7f62692ebd Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 18 Jul 2018 13:46:17 -0700 Subject: [PATCH] Add local plugin repair support. Update global repair implementation. --- .../commands/plugin/action/repair_plugins.rb | 27 +++++++++++++++++-- plugins/commands/plugin/command/repair.rb | 12 ++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/plugins/commands/plugin/action/repair_plugins.rb b/plugins/commands/plugin/action/repair_plugins.rb index 9745d378b..0d13907dd 100644 --- a/plugins/commands/plugin/action/repair_plugins.rb +++ b/plugins/commands/plugin/action/repair_plugins.rb @@ -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 diff --git a/plugins/commands/plugin/command/repair.rb b/plugins/commands/plugin/command/repair.rb index 6deff6ae2..a531e01b2 100644 --- a/plugins/commands/plugin/command/repair.rb +++ b/plugins/commands/plugin/command/repair.rb @@ -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