From fe1cd06da838d73add4d89a5ee00856c2703fd00 Mon Sep 17 00:00:00 2001 From: cgoldfeder Date: Thu, 16 Jun 2016 19:13:08 -0700 Subject: [PATCH] Remove some cruft in CommandUtilities ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125127487 --- .../registry/tools/CommandUtilities.java | 27 +------------------ .../registry/tools/ConfirmingCommand.java | 10 ++++++- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/java/google/registry/tools/CommandUtilities.java b/java/google/registry/tools/CommandUtilities.java index 8f1d71d06..95cd72689 100644 --- a/java/google/registry/tools/CommandUtilities.java +++ b/java/google/registry/tools/CommandUtilities.java @@ -25,31 +25,6 @@ class CommandUtilities { /** Prompts for yes/no input using promptText, defaulting to no. */ static boolean promptForYes(String promptText) { - return promptForYesOrNo(promptText, false); - } - - /** - * Prompts for yes/no input using promptText and returns true for yes and false for no, using - * defaultResponse as the response for empty input. - */ - static boolean promptForYesOrNo(String promptText, boolean defaultResponse) { - String options = defaultResponse ? "Y/n" : "y/N"; - while (true) { - String line = System.console().readLine(String.format("%s (%s): ", promptText, options)); - if (line.isEmpty()) { - return defaultResponse; - } else if ("Y".equalsIgnoreCase(line.substring(0, 1))) { - return true; - } else if ("N".equalsIgnoreCase(line.substring(0, 1))) { - return false; - } - } - } - - /** Prints the provided text with a trailing newline, if text is not null or empty. */ - static void printLineIfNotEmpty(String text) { - if (!Strings.isNullOrEmpty(text)) { - System.out.println(text); - } + return System.console().readLine(promptText + " (y/N): ").toUpperCase().startsWith("Y"); } } diff --git a/java/google/registry/tools/ConfirmingCommand.java b/java/google/registry/tools/ConfirmingCommand.java index b9b26bfd3..29431fd4a 100644 --- a/java/google/registry/tools/ConfirmingCommand.java +++ b/java/google/registry/tools/ConfirmingCommand.java @@ -14,9 +14,10 @@ package google.registry.tools; -import static google.registry.tools.CommandUtilities.printLineIfNotEmpty; import static google.registry.tools.CommandUtilities.promptForYes; +import com.google.common.base.Strings; + import com.beust.jcommander.Parameter; /** A {@link Command} that implements a confirmation step before executing. */ @@ -64,4 +65,11 @@ public abstract class ConfirmingCommand implements Command { protected String postExecute() throws Exception { return ""; } + + /** Prints the provided text with a trailing newline, if text is not null or empty. */ + private static void printLineIfNotEmpty(String text) { + if (!Strings.isNullOrEmpty(text)) { + System.out.println(text); + } + } }