Include plugin repair command

This commit is contained in:
Chris Roberts 2016-11-02 10:37:29 -07:00
parent 3fb5913af1
commit 5d68c8c30b
5 changed files with 80 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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: |-