From 5d68c8c30b3583a68cd803c8862883ba75c90c62 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 2 Nov 2016 10:37:29 -0700 Subject: [PATCH] Include plugin repair command --- plugins/commands/plugin/action.rb | 8 +++++ .../commands/plugin/action/repair_plugins.rb | 31 +++++++++++++++++++ plugins/commands/plugin/command/repair.rb | 28 +++++++++++++++++ plugins/commands/plugin/command/root.rb | 5 +++ templates/locales/en.yml | 8 +++++ 5 files changed, 80 insertions(+) create mode 100644 plugins/commands/plugin/action/repair_plugins.rb create mode 100644 plugins/commands/plugin/command/repair.rb diff --git a/plugins/commands/plugin/action.rb b/plugins/commands/plugin/action.rb index 832bc3508..cdc9c3943 100644 --- a/plugins/commands/plugin/action.rb +++ b/plugins/commands/plugin/action.rb @@ -27,6 +27,13 @@ module VagrantPlugins end end + # This middleware sequence will repair installed plugins. + def self.action_repair + Vagrant::Action::Builder.new.tap do |b| + b.use RepairPlugins + end + end + # This middleware sequence will uninstall a plugin. def self.action_uninstall Vagrant::Action::Builder.new.tap do |b| @@ -48,6 +55,7 @@ module VagrantPlugins autoload :LicensePlugin, action_root.join("license_plugin") autoload :ListPlugins, action_root.join("list_plugins") autoload :PluginExistsCheck, action_root.join("plugin_exists_check") + autoload :RepairPlugins, action_root.join("repair_plugins") autoload :UninstallPlugin, action_root.join("uninstall_plugin") autoload :UpdateGems, action_root.join("update_gems") end diff --git a/plugins/commands/plugin/action/repair_plugins.rb b/plugins/commands/plugin/action/repair_plugins.rb new file mode 100644 index 000000000..3ce886b3f --- /dev/null +++ b/plugins/commands/plugin/action/repair_plugins.rb @@ -0,0 +1,31 @@ +require "vagrant/plugin/manager" + +module VagrantPlugins + module CommandPlugin + module Action + # This middleware attempts to repair installed plugins. + # + # In general, if plugins are failing to properly load the + # core issue will likely be one of two issues: + # 1. manual modifications within ~/.vagrant.d/ + # 2. vagrant upgrade + # Running an install on configured plugin set will most + # likely fix these issues, which is all this action does. + class RepairPlugins + def initialize(app, env) + @app = app + end + + def call(env) + env[:ui].info(I18n.t("vagrant.commands.plugin.repairing")) + plugins = Vagrant::Plugin::Manager.instance.installed_plugins + Vagrant::Bundler.instance.init!(plugins, :repair) + env[:ui].info(I18n.t("vagrant.commands.plugin.repair_complete")) + + # 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 new file mode 100644 index 000000000..6deff6ae2 --- /dev/null +++ b/plugins/commands/plugin/command/repair.rb @@ -0,0 +1,28 @@ +require 'optparse' + +require_relative "base" + +module VagrantPlugins + module CommandPlugin + module Command + class Repair < Base + def execute + opts = OptionParser.new do |o| + o.banner = "Usage: vagrant plugin repair [-h]" + end + + # Parse the options + argv = parse_options(opts) + return if !argv + raise Vagrant::Errors::CLIInvalidUsage, help: opts.help.chomp if argv.length > 0 + + # Attempt to repair installed plugins + action(Action.action_repair) + + # Success, exit status 0 + 0 + end + end + end + end +end diff --git a/plugins/commands/plugin/command/root.rb b/plugins/commands/plugin/command/root.rb index 8c4d1ad1b..9a53f6883 100644 --- a/plugins/commands/plugin/command/root.rb +++ b/plugins/commands/plugin/command/root.rb @@ -29,6 +29,11 @@ module VagrantPlugins List end + @subcommands.register(:repair) do + require_relative "repair" + Repair + end + @subcommands.register(:update) do require_relative "update" Update diff --git a/templates/locales/en.yml b/templates/locales/en.yml index d3114d845..250d89be4 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1601,6 +1601,14 @@ en: post_install: |- Post install message from the '%{name}' plugin: + %{message} + repairing: |- + Repairing currently installed plugins. This may take a few minutes... + repair_complete: |- + Installed plugins successfully repaired! + repair_failed: |- + Failed to automatically repair installed Vagrant plugins. Failure message: + %{message} snapshot: not_supported: |-