| | |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.util.Utils; |
| | | |
| | | import com.forgerock.opendj.cli.Argument; |
| | | import com.forgerock.opendj.cli.ArgumentException; |
| | | import com.forgerock.opendj.cli.ArgumentGroup; |
| | | import com.forgerock.opendj.cli.BooleanArgument; |
| | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void appendUsage(StringBuilder sb, SubCommand sc, String argLongID) { |
| | | final String toolName = "dsconfig"; |
| | | final SubCommandHandler sch = handlers.get(sc); |
| | | final RelationDefinition<?, ?> rd = getRelationDefinition(sch); |
| | | if (rd instanceof InstantiableRelationDefinition) { |
| | |
| | | final List<PropertyDefinition<?>> props = |
| | | new ArrayList<PropertyDefinition<?>>(defn.getAllPropertyDefinitions()); |
| | | Collections.sort(props); |
| | | final String propPrefix = toolName + "-" + sc.getName() + "-" + argLongID + "-"; |
| | | |
| | | final String propPrefix = DSCONFIGTOOLNAME + "-" + sc.getName() + "-" + argLongID + "-"; |
| | | sb.append(EOL); |
| | | toSimpleList(props, propPrefix, sb); |
| | | sb.append(EOL); |
| | |
| | | @Override |
| | | public MenuResult<Integer> invoke(ConsoleApplication app) throws ClientException { |
| | | try { |
| | | MenuResult<Integer> result = handler.run(app, factory); |
| | | |
| | | final MenuResult<Integer> result = handler.run(app, factory); |
| | | if (result.isQuit()) { |
| | | return result; |
| | | } else { |
| | |
| | | app.println(); |
| | | app.println(); |
| | | |
| | | MenuResult<Integer> result = menu.run(); |
| | | |
| | | final MenuResult<Integer> result = menu.run(); |
| | | if (result.isCancel()) { |
| | | return MenuResult.again(); |
| | | } |
| | |
| | | |
| | | private void checkForConflictingArguments() throws ArgumentException { |
| | | if (quietArgument.isPresent() && verboseArgument.isPresent()) { |
| | | final LocalizableMessage message = ERR_TOOL_CONFLICTING_ARGS.get(quietArgument.getLongIdentifier(), |
| | | verboseArgument.getLongIdentifier()); |
| | | throw new ArgumentException(message); |
| | | throw conflictingArgs(quietArgument, verboseArgument); |
| | | } |
| | | |
| | | if (batchFileArgument.isPresent() && !noPromptArgument.isPresent()) { |
| | |
| | | } |
| | | |
| | | if (scriptFriendlyArgument.isPresent() && verboseArgument.isPresent()) { |
| | | final LocalizableMessage message = ERR_TOOL_CONFLICTING_ARGS.get( |
| | | scriptFriendlyArgument.getLongIdentifier(), verboseArgument.getLongIdentifier()); |
| | | throw new ArgumentException(message); |
| | | throw conflictingArgs(scriptFriendlyArgument, verboseArgument); |
| | | } |
| | | |
| | | if (noPropertiesFileArgument.isPresent() && propertiesFileArgument.isPresent()) { |
| | | final LocalizableMessage message = ERR_TOOL_CONFLICTING_ARGS.get( |
| | | noPropertiesFileArgument.getLongIdentifier(), propertiesFileArgument.getLongIdentifier()); |
| | | throw new ArgumentException(message); |
| | | throw conflictingArgs(noPropertiesFileArgument, propertiesFileArgument); |
| | | } |
| | | } |
| | | |
| | | private ArgumentException conflictingArgs(Argument arg1, Argument arg2) { |
| | | return new ArgumentException(ERR_TOOL_CONFLICTING_ARGS.get(arg1.getLongIdentifier(), arg2.getLongIdentifier())); |
| | | } |
| | | |
| | | /** Run the top-level interactive console. */ |
| | | private int runInteractiveMode() { |
| | | |
| | |
| | | app.println(); |
| | | |
| | | final MenuResult<Integer> result = menu.run(); |
| | | |
| | | if (result.isQuit()) { |
| | | return ReturnCode.SUCCESS.get(); |
| | | } else { |
| | |
| | | private int runSubCommand(SubCommandHandler handler) { |
| | | try { |
| | | final MenuResult<Integer> result = handler.run(this, factory); |
| | | |
| | | if (result.isSuccess()) { |
| | | if (isInteractive() && handler.isCommandBuilderUseful()) { |
| | | printCommandBuilder(getCommandBuilder(handler)); |
| | |
| | | * @return <T> The builded command. |
| | | */ |
| | | <T> CommandBuilder getCommandBuilder(final T subCommand) { |
| | | String commandName = System.getProperty(PROPERTY_SCRIPT_NAME); |
| | | if (commandName == null) { |
| | | commandName = DSCONFIGTOOLNAME; |
| | | } |
| | | CommandBuilder commandBuilder = null; |
| | | final String commandName = getCommandName(); |
| | | final String subCommandName; |
| | | if (subCommand instanceof SubCommandHandler) { |
| | | commandBuilder = new CommandBuilder(commandName, |
| | | ((SubCommandHandler) subCommand).getSubCommand().getName()); |
| | | subCommandName = ((SubCommandHandler) subCommand).getSubCommand().getName(); |
| | | } else { |
| | | commandBuilder = new CommandBuilder(commandName, (String) subCommand); |
| | | subCommandName = (String) subCommand; |
| | | } |
| | | final CommandBuilder commandBuilder = new CommandBuilder(commandName, subCommandName); |
| | | if (factory != null && factory.getContextCommandBuilder() != null) { |
| | | commandBuilder.append(factory.getContextCommandBuilder()); |
| | | } |
| | |
| | | return commandBuilder; |
| | | } |
| | | |
| | | private String getCommandName() { |
| | | final String commandName = System.getProperty(PROPERTY_SCRIPT_NAME); |
| | | if (commandName != null && commandName.length() != 0) { |
| | | return commandName; |
| | | } |
| | | return DSCONFIGTOOLNAME; |
| | | } |
| | | |
| | | /** |
| | | * Prints the contents of a command builder. This method has been created since SetPropSubCommandHandler calls it. |
| | | * All the logic of DSConfig is on this method. It writes the content of the CommandBuilder to the standard output, |
| | |
| | | * session started. |
| | | */ |
| | | private String getSessionStartTimeMessage() { |
| | | String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME); |
| | | if (scriptName == null || scriptName.length() == 0) { |
| | | scriptName = DSCONFIGTOOLNAME; |
| | | } |
| | | final String date = formatDateTimeStringForEquivalentCommand(new Date(sessionStartTime)); |
| | | return INFO_DSCFG_SESSION_START_TIME_MESSAGE.get(scriptName, date).toString(); |
| | | return INFO_DSCFG_SESSION_START_TIME_MESSAGE.get(getCommandName(), date).toString(); |
| | | } |
| | | |
| | | private void handleBatchFile(String[] args) { |