From f045f74d86cefa36a099b7d190a8ae0b59555726 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Mon, 7 Nov 2016 19:25:32 -0800 Subject: [PATCH] Only proceed if confirmation is matched. Do not continue if user aborted. --- .../commands/plugin/action/expunge_plugins.rb | 34 ++++++++++--------- templates/locales/en.yml | 3 ++ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/plugins/commands/plugin/action/expunge_plugins.rb b/plugins/commands/plugin/action/expunge_plugins.rb index 4c61d9145..0debc5803 100644 --- a/plugins/commands/plugin/action/expunge_plugins.rb +++ b/plugins/commands/plugin/action/expunge_plugins.rb @@ -1,4 +1,3 @@ -require 'pp' require "vagrant/plugin/manager" module VagrantPlugins @@ -22,26 +21,29 @@ module VagrantPlugins I18n.t("vagrant.commands.plugin.expunge_confirm") + " [Y/N]:" ) - if result.to_s.downcase.strip == 'n' - exit 1 + if result.to_s.downcase.strip != 'y' + abort_action = true end end - plugins = Vagrant::Plugin::Manager.instance.installed_plugins - plugins_json = File.join(env[:home_path], "plugins.json") - plugins_gems = env[:gems_path] + if !abort_action + plugins_json = File.join(env[:home_path], "plugins.json") + plugins_gems = env[:gems_path] - if File.exist?(plugins_json) - FileUtils.rm(plugins_json) + if File.exist?(plugins_json) + FileUtils.rm(plugins_json) + end + + if File.directory?(plugins_gems) + FileUtils.rm_rf(plugins_gems) + end + + env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_complete")) + + @app.call(env) + else + env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_aborted")) end - - if File.directory?(plugins_gems) - FileUtils.rm_rf(plugins_gems) - end - - env[:ui].info(I18n.t("vagrant.commands.plugin.expunge_complete")) - - @app.call(env) end end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index e3ce3f37a..88099cedb 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -1591,6 +1591,9 @@ en: expunge_reinstall: |- Vagrant will now attempt to reinstall user plugins that were removed. + expunge_aborted: |- + + Vagrant expunge has been declined. Skipping removal of plugins. installed_license: |- The license for '%{name}' was successfully installed! installing_license: |-