From 4bbd43c73f4b04a0482bcc453c078df1f04b5f32 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Thu, 12 Jan 2017 07:16:57 -0800 Subject: [PATCH] Display default on expunge command questions. Prompt user on invalid input. --- .../commands/plugin/action/expunge_plugins.rb | 25 +++++++++++++++---- plugins/commands/plugin/command/expunge.rb | 23 +++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/plugins/commands/plugin/action/expunge_plugins.rb b/plugins/commands/plugin/action/expunge_plugins.rb index 0debc5803..072ef81a6 100644 --- a/plugins/commands/plugin/action/expunge_plugins.rb +++ b/plugins/commands/plugin/action/expunge_plugins.rb @@ -17,11 +17,26 @@ module VagrantPlugins def call(env) if !env[:force] - result = env[:ui].ask( - I18n.t("vagrant.commands.plugin.expunge_confirm") + - " [Y/N]:" - ) - if result.to_s.downcase.strip != 'y' + + result = nil + attempts = 0 + while attempts < 5 && result.nil? + attempts += 1 + result = env[:ui].ask( + I18n.t("vagrant.commands.plugin.expunge_confirm") + + " [N]: " + ) + result = result.to_s.downcase.strip + result = "n" if result.empty? + if !["y", "yes", "n", "no"].include?(result) + result = nil + env[:ui].error("Please answer Y or N") + else + result = result[0,1] + end + end + + if result != 'y' abort_action = true end end diff --git a/plugins/commands/plugin/command/expunge.rb b/plugins/commands/plugin/command/expunge.rb index 720e699b0..6ec16ea9d 100644 --- a/plugins/commands/plugin/command/expunge.rb +++ b/plugins/commands/plugin/command/expunge.rb @@ -29,11 +29,24 @@ module VagrantPlugins plugins = Vagrant::Plugin::Manager.instance.installed_plugins if !options[:reinstall] && !options[:force] && !plugins.empty? - result = @env.ui.ask( - I18n.t("vagrant.commands.plugin.expunge_request_reinstall") + - " [Y/N]:" - ) - options[:reinstall] = result.to_s.downcase.strip == "y" + result = nil + attempts = 0 + while attempts < 5 && result.nil? + attempts += 1 + result = @env.ui.ask( + I18n.t("vagrant.commands.plugin.expunge_request_reinstall") + + " [N]: " + ) + result = result.to_s.downcase.strip + result = "n" if result.empty? + if !["y", "yes", "n", "no"].include?(result) + result = nil + @env.ui.error("Please answer Y or N") + else + result = result[0,1] + end + end + options[:reinstall] = result == "y" end # Remove all installed user plugins