@Override public boolean promptBoolean(final String message, final boolean defaultIfEmpty) { return prompt(message, Boolean.class, defaultIfEmpty); }
@Override public String prompt() { return prompt(""); }
@Override public String prompt(final String message, final String defaultIfEmpty) { return prompt(message, String.class, defaultIfEmpty); }
@Override public String promptRegex(final String message, final String regex) { String input; do { input = prompt(message); } while (!input.matches(regex)); return input; }
@Override public String promptRegex(final String message, final String pattern, final String defaultIfEmpty) { if (this.isAcceptDefaults()) { return defaultIfEmpty; } if (!defaultIfEmpty.matches(pattern)) { throw new IllegalArgumentException("Default value [" + defaultIfEmpty + "] does not match required pattern [" + pattern + "]"); } String input; do { String query = " [" + defaultIfEmpty + "] "; input = prompt(message + query); if ("".equals(input.trim())) { input = defaultIfEmpty; } } while (!input.matches(pattern)); return input; }
@Override @SuppressWarnings("unchecked") public <T> T prompt(final String message, final Class<T> clazz) { Object result; Object input; do { input = prompt(message); try { result = DataConversion.convert(input, clazz); } catch (Exception e) { result = InvalidInput.INSTANCE; } } while ((result instanceof InvalidInput)); return (T) result; }
input = prompt(message + query); if ((input == null) || "".equals(input.trim()))
@Override public String promptCommon(final String message, final PromptType type) { String input; do { input = prompt(message); } while (!type.matches(input)); input = getPromptTypeConverter().convert(type, input); return input; }
int input = prompt("Choose an option by typing the number of the selection: ", Integer.class) - 1; if ((input >= 0) && (input < options.size()))
int input = prompt( "Choose an option by typing the number of the selection " + renderColor(ShellColor.BOLD, "[*-default] "),
int input = prompt("Choose an option by typing the number of the selection: ", Integer.class) - 1; if (input < options.size())
@Override public String promptCommon(final String message, final PromptType type, final String defaultIfEmpty) { if (this.isAcceptDefaults()) { return defaultIfEmpty; } if (!type.matches(defaultIfEmpty)) { throw new IllegalArgumentException("Default value [" + defaultIfEmpty + "] is not a valid match for the given prompt type [" + type.name() + "]"); } String input; do { String query = " [" + defaultIfEmpty + "] "; input = prompt(message + query); if ((input == null) || input.isEmpty()) { input = defaultIfEmpty; } } while (!type.matches(input)); input = getPromptTypeConverter().convert(type, input); return input; }