| | |
| | | import static org.opends.messages.AdminToolMessages.*; |
| | | import static org.opends.messages.ToolMessages.*; |
| | | import static org.opends.messages.QuickSetupMessages.*; |
| | | import static org.opends.server.tools.ToolConstants.*; |
| | | |
| | | import org.opends.quicksetup.util.Utils; |
| | | import org.opends.server.admin.client.cli.SecureConnectionCliParser; |
| | | import org.opends.server.util.args.ArgumentParser; |
| | | import org.opends.server.util.args.ArgumentException; |
| | | import org.opends.server.util.args.BooleanArgument; |
| | |
| | | Logger.getLogger(CliApplicationHelper.class.getName()); |
| | | |
| | | /** Format string used for deriving the console prompt. */ |
| | | static public final String PROMPT_FORMAT = "%s%n[%s]:"; |
| | | static public final String PROMPT_DEFAULT_FORMAT = "%s%n[%s]:"; |
| | | |
| | | /** Format string used for deriving the console prompt. */ |
| | | static public final String PROMPT_NO_DEFAULT_FORMAT = "%s"; |
| | | |
| | | private BooleanArgument noPromptArg = null; |
| | | |
| | |
| | | while (!isValid) |
| | | { |
| | | |
| | | Message msg = Message.raw(PROMPT_FORMAT, prompt, defaultValue); |
| | | Message msg; |
| | | |
| | | if (defaultValue == null) |
| | | { |
| | | |
| | | msg = Message.raw(PROMPT_NO_DEFAULT_FORMAT, prompt, defaultValue); |
| | | } |
| | | else |
| | | { |
| | | msg = Message.raw(PROMPT_DEFAULT_FORMAT, prompt, defaultValue); |
| | | } |
| | | |
| | | out.print(msg); |
| | | out.flush(); |
| | |
| | | Utils.getCommandLineMaxLineWidth()); |
| | | |
| | | while (true) { |
| | | out.print(wrappedPrompt); |
| | | |
| | | if (defaultValue == null) { |
| | | out.print(": "); |
| | | out.print(wrappedPrompt); |
| | | out.print(" "); |
| | | } else { |
| | | out.println(wrappedPrompt); |
| | | out.print("["); |
| | | out.print(defaultValue); |
| | | out.print("]: "); |
| | |
| | | // them with the parser. |
| | | try { |
| | | noPromptArg = new BooleanArgument( |
| | | SecureConnectionCliParser.NO_PROMPT_OPTION_LONG, |
| | | SecureConnectionCliParser.NO_PROMPT_OPTION_SHORT, |
| | | SecureConnectionCliParser.NO_PROMPT_OPTION_LONG, |
| | | OPTION_LONG_NO_PROMPT, |
| | | OPTION_SHORT_NO_PROMPT, |
| | | OPTION_LONG_NO_PROMPT, |
| | | INFO_DESCRIPTION_NO_PROMPT.get()); |
| | | argParser.addArgument(noPromptArg); |
| | | |
| | | quietArg = |
| | | new BooleanArgument( |
| | | SecureConnectionCliParser.QUIET_OPTION_LONG, |
| | | SecureConnectionCliParser.QUIET_OPTION_SHORT, |
| | | SecureConnectionCliParser.QUIET_OPTION_LONG, |
| | | OPTION_LONG_QUIET, |
| | | OPTION_SHORT_QUIET, |
| | | OPTION_LONG_QUIET, |
| | | INFO_DESCRIPTION_QUIET.get()); |
| | | argParser.addArgument(quietArg); |
| | | |
| | |
| | | return argParser; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Displays an error message in the error output (wrapping it if necessary). |
| | | * @param msg the error message to be displayed. |
| | |
| | | { |
| | | err.println(org.opends.server.util.StaticUtils.wrapText(msg, |
| | | Utils.getCommandLineMaxLineWidth())); |
| | | LOG.log(Level.SEVERE, msg.toString()); |
| | | } |
| | | |
| | | /** |
| | | * Displays a progress message in the error output (wrapping it if necessary). |
| | | * @param msg the error message to be displayed. |
| | | */ |
| | | protected void printProgressMessage(Message msg) |
| | | { |
| | | if (!isQuiet()) |
| | | { |
| | | out.print(org.opends.server.util.StaticUtils.wrapText(msg, |
| | | Utils.getCommandLineMaxLineWidth())); |
| | | out.flush(); |
| | | } |
| | | LOG.log(Level.INFO, msg.toString()); |
| | | } |
| | | |
| | | /** |
| | | * Displays a progress message in the error output (wrapping it if necessary). |
| | | * @param msg the error message to be displayed. |
| | | */ |
| | | protected void printProgressMessage(String msg) |
| | | { |
| | | if (!isQuiet()) |
| | | { |
| | | out.print(org.opends.server.util.StaticUtils.wrapText(msg, |
| | | Utils.getCommandLineMaxLineWidth())); |
| | | out.flush(); |
| | | } |
| | | LOG.log(Level.INFO, msg.toString()); |
| | | } |
| | | |
| | | /** |
| | | * Prints a line break in the standard output if we are not in quite mode. |
| | | */ |
| | | protected void printProgressLineBreak() |
| | | { |
| | | if (!isQuiet()) |
| | | { |
| | | out.println(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Displays a warning message in the error output (wrapping it if necessary). |
| | | * @param msg the warning message to be displayed. |
| | | */ |
| | | protected void printWarningMessage(Message msg) |
| | | { |
| | | if (!isQuiet()) |
| | | { |
| | | // TODO: decide if even in quiet mode we must display this message or not. |
| | | out.println(org.opends.server.util.StaticUtils.wrapText(msg, |
| | | Utils.getCommandLineMaxLineWidth())); |
| | | out.flush(); |
| | | } |
| | | LOG.log(Level.WARNING, msg.toString()); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * Prints a line message in the standard output. |
| | | * @param msg the error message to be displayed. |
| | | * @param overrideQuietMode whether to override the quiet mode or not. |
| | | */ |
| | | protected void printLine(Message msg, boolean overrideQuietMode) |
| | | { |
| | | if (!isQuiet() || overrideQuietMode) |
| | | { |
| | | out.println(org.opends.server.util.StaticUtils.wrapText(msg, |
| | | Utils.getCommandLineMaxLineWidth())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Prompts the user to give the Global Administrator UID. |
| | | * @param defaultValue the default value that will be proposed in the prompt |
| | | * message. |