mirror of
https://github.com/google/nomulus.git
synced 2025-05-13 07:57:13 +02:00
Remove some cruft in CommandUtilities
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=125127487
This commit is contained in:
parent
1d2d81492e
commit
fe1cd06da8
2 changed files with 10 additions and 27 deletions
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue