From 769a4f06af790ddd713bb280ffd5f657886ae90a Mon Sep 17 00:00:00 2001
From: Violette Roche-Montane <violette.roche-montane@forgerock.com>
Date: Wed, 12 Feb 2014 16:11:06 +0000
Subject: [PATCH] Checkpoint commit for OPENDJ-1343 Migrate dsconfig / OPENDJ-1303 "opendj-cli" - added classes needeed by DSConfig.
---
opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConsoleApplication.java | 84 +++++++++++++++++++++++++++++++++++++++---
1 files changed, 78 insertions(+), 6 deletions(-)
diff --git a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConsoleApplication.java b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConsoleApplication.java
index 3811989..a17ca6f 100755
--- a/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConsoleApplication.java
+++ b/opendj-sdk/opendj-cli/src/main/java/com/forgerock/opendj/cli/ConsoleApplication.java
@@ -30,6 +30,7 @@
import static com.forgerock.opendj.cli.CliMessages.INFO_ERROR_EMPTY_RESPONSE;
import static com.forgerock.opendj.cli.CliMessages.INFO_MENU_PROMPT_RETURN_TO_CONTINUE;
import static com.forgerock.opendj.cli.CliMessages.INFO_PROMPT_SINGLE_DEFAULT;
+import static com.forgerock.opendj.cli.CliMessages.ERR_TRIES_LIMIT_REACHED;
import static com.forgerock.opendj.cli.Utils.MAX_LINE_WIDTH;
import static com.forgerock.opendj.cli.Utils.wrapText;
@@ -144,6 +145,15 @@
}
/**
+ * Indicates whether or not the user has requested advanced mode.
+ *
+ * @return Returns <code>true</code> if the user has requested advanced mode.
+ */
+ public boolean isAdvancedMode() {
+ return false;
+ }
+
+ /**
* Interactively prompts the user to press return to continue. This method should be called in situations where a
* user needs to be given a chance to read some documentation before continuing (continuing may cause the
* documentation to be scrolled out of view).
@@ -215,14 +225,18 @@
* The message.
*/
public final void print(final LocalizableMessage msg) {
- out.print(wrap(msg));
+ if (!isQuiet()) {
+ out.print(wrap(msg));
+ }
}
/**
* Displays a blank line to the output stream.
*/
public final void println() {
- out.println();
+ if (!isQuiet()) {
+ out.println();
+ }
}
/**
@@ -232,7 +246,9 @@
* The message.
*/
public final void println(final LocalizableMessage msg) {
- out.println(wrap(msg));
+ if (!isQuiet()) {
+ out.println(wrap(msg));
+ }
}
/**
@@ -244,7 +260,9 @@
* The number of columns to indent.
*/
public final void println(final LocalizableMessage msg, final int indent) {
- out.println(wrapText(msg, MAX_LINE_WIDTH, indent));
+ if (!isQuiet()) {
+ out.println(wrapText(msg, MAX_LINE_WIDTH, indent));
+ }
}
/**
@@ -254,7 +272,7 @@
* The verbose message.
*/
public final void printVerboseMessage(final LocalizableMessage msg) {
- if (isVerbose() || isInteractive()) {
+ if (isVerbose()) {
out.println(wrap(msg));
}
}
@@ -330,7 +348,7 @@
* @throws ClientException
* If the line of input could not be retrieved for some reason.
*/
- private final String readLineOfInput(final LocalizableMessage prompt) throws ClientException {
+ final String readLineOfInput(final LocalizableMessage prompt) throws ClientException {
if (prompt != null) {
err.print(wrap(prompt));
err.print(" ");
@@ -348,6 +366,60 @@
}
/**
+ * Interactively prompts for user input and continues until valid input is provided.
+ *
+ * @param <T>
+ * The type of decoded user input.
+ * @param prompt
+ * The interactive prompt which should be displayed on each input attempt.
+ * @param validator
+ * An input validator responsible for validating and decoding the user's response.
+ * @return Returns the decoded user's response.
+ * @throws ClientException
+ * If an unexpected error occurred which prevented validation.
+ */
+ public final <T> T readValidatedInput(final LocalizableMessage prompt, final ValidationCallback<T> validator)
+ throws ClientException {
+ while (true) {
+ final String response = readLineOfInput(prompt);
+ final T value = validator.validate(this, response);
+ if (value != null) {
+ return value;
+ }
+ }
+ }
+
+ /**
+ * Interactively prompts for user input and continues until valid input is provided.
+ *
+ * @param <T>
+ * The type of decoded user input.
+ * @param prompt
+ * The interactive prompt which should be displayed on each input attempt.
+ * @param validator
+ * An input validator responsible for validating and decoding the user's response.
+ * @param maxTries
+ * The maximum number of tries that we can make.
+ * @return Returns the decoded user's response.
+ * @throws ClientException
+ * If an unexpected error occurred which prevented validation or
+ * if the maximum number of tries was reached.
+ */
+ public final <T> T readValidatedInput(final LocalizableMessage prompt, final ValidationCallback<T> validator,
+ final int maxTries) throws ClientException {
+ int nTries = 0;
+ while (nTries < maxTries) {
+ final String response = readLineOfInput(prompt);
+ final T value = validator.validate(this, response);
+ if (value != null) {
+ return value;
+ }
+ nTries++;
+ }
+ throw new ClientException(ReturnCode.ERROR_USER_DATA, ERR_TRIES_LIMIT_REACHED.get(maxTries));
+ }
+
+ /**
* Inserts line breaks into the provided buffer to wrap text at no more than the specified column width (80).
*
* @param msg
--
Gitblit v1.10.0