/** * Prompts the user for a yes or no answer to the specified question until they provide a valid * response (y/n/yes/no case insensitive) and reports the result. If yesNoPrompt is called in * non-interactive mode, an IllegalStateException is thrown. * * @param question The question to which a yes or no is expected in response. * @return <code>true</code> if the user answer yes, <code>false</code> if the user answered no. * @throws IOException if there is a problem reading from the terminal. */ protected final boolean yesNoPrompt(String question) throws IOException { return confirmationPrompt(question, YES_OR_NO_HINT, YES_PATTERN, NO_PATTERN); }
/** * Prompts the user to specifically type in a specified user string for a specified question * and reports the result. This is primarily used for dangerous operations such as deleting or * uninstalling a Fiji table or instance. If inputConfirmation is called in non-interactive * mode, an IllegalStateException is thrown. * * @param question The question to which the user is expected to respond to. * @param confirm The requested input(such as instance or table name) to validate against. * @return <code>true</code> if the string was entered successfully, <code>false</code> if not. * @throws IOException if there is a problem reading from the terminal. */ protected final boolean inputConfirmation(String question, String confirm) throws IOException { String hint = String.format("Type '%s' without the quotes to confirm(or nothing to cancel):", confirm); Pattern confirmPattern = Pattern.compile(Pattern.quote(confirm), Pattern.CASE_INSENSITIVE); return confirmationPrompt(question, hint, confirmPattern, ALL_PATTERN); }