2016-11-04 15:00:43 +00:00
|
|
|
require "vagrant/plugin/manager"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandPlugin
|
|
|
|
module Action
|
|
|
|
# This middleware removes user installed plugins by
|
|
|
|
# removing:
|
|
|
|
# * ~/.vagrant.d/plugins.json
|
|
|
|
# * ~/.vagrant.d/gems
|
|
|
|
# Usage should be restricted to when a repair is
|
|
|
|
# unsuccessful and the only reasonable option remaining
|
|
|
|
# is to re-install all plugins
|
|
|
|
class ExpungePlugins
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
if !env[:force]
|
|
|
|
result = env[:ui].ask(
|
|
|
|
I18n.t("vagrant.commands.plugin.expunge_confirm") +
|
|
|
|
" [Y/N]:"
|
|
|
|
)
|
2016-11-08 03:25:32 +00:00
|
|
|
if result.to_s.downcase.strip != 'y'
|
|
|
|
abort_action = true
|
2016-11-04 15:00:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
if !abort_action
|
|
|
|
plugins_json = File.join(env[:home_path], "plugins.json")
|
|
|
|
plugins_gems = env[:gems_path]
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
if File.exist?(plugins_json)
|
|
|
|
FileUtils.rm(plugins_json)
|
|
|
|
end
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
if File.directory?(plugins_gems)
|
|
|
|
FileUtils.rm_rf(plugins_gems)
|
|
|
|
end
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_complete"))
|
2016-11-04 15:00:43 +00:00
|
|
|
|
2016-11-08 03:25:32 +00:00
|
|
|
@app.call(env)
|
|
|
|
else
|
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_aborted"))
|
|
|
|
end
|
2016-11-04 15:00:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|