mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
17.58.2007 2e84375dc07d24f52ccc5d247b350e18de517eba
Fix for issue 2278.

Update the wrapping code to take into consideration the Windows constraints.
2 files modified
56 ■■■■■ changed files
opends/src/server/org/opends/server/util/args/ArgumentParser.java 28 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java 28 ●●●●● patch | view | raw | blame | history
opends/src/server/org/opends/server/util/args/ArgumentParser.java
@@ -42,6 +42,7 @@
import java.util.Set;
import org.opends.server.core.DirectoryServer;
import org.opends.server.util.SetupUtils;
import static org.opends.messages.UtilityMessages.*;
import static org.opends.server.util.ServerConstants.*;
@@ -167,6 +168,9 @@
          INFO_DESCRIPTION_GENERAL_ARGS.get(), Integer.MIN_VALUE);
  private final static String INDENT = "    ";
  private final static int MAX_LENGTH = SetupUtils.isWindows() ? 79 : 80;
  /**
   * Creates a new instance of this argument parser with no arguments.
   * Unnamed trailing arguments will not be allowed.
@@ -1338,7 +1342,7 @@
    usageOrVersionDisplayed = true;
    if ((toolDescription != null) && (toolDescription.length() > 0))
    {
      buffer.append(wrapText(toolDescription.toString(), 79));
      buffer.append(wrapText(toolDescription.toString(), MAX_LENGTH - 1));
      buffer.append(EOL);
      buffer.append(EOL);
    }
@@ -1385,7 +1389,7 @@
        Message groupDesc = argGroup.getDescription();
        if (groupDesc != null && !Message.EMPTY.equals(groupDesc)) {
          buffer.append(EOL);
          buffer.append(wrapText(groupDesc.toString(), 79));
          buffer.append(wrapText(groupDesc.toString(), MAX_LENGTH - 1));
          buffer.append(EOL);
          buffer.append(EOL);
        }
@@ -1503,6 +1507,7 @@
    // Write a line with the short and/or long identifiers that may be
    // used
    // for the argument.
    final int indentLength = INDENT.length();
    Character shortID = a.getShortIdentifier();
    String longID = a.getLongIdentifier();
    if (shortID != null)
@@ -1537,7 +1542,7 @@
        int lineLength = (buffer.length() - currentLength) +
                         newBuffer.length();
        if (lineLength > 80)
        if (lineLength > MAX_LENGTH)
        {
          buffer.append(EOL);
          buffer.append(newBuffer.toString());
@@ -1578,21 +1583,22 @@
    // at or
    // before column 79 so it will be friendly to 80-column displays.
    Message description = a.getDescription();
    if (description.length() <= 75)
    int descMaxLength = MAX_LENGTH - indentLength - 1;
    if (description.length() <= descMaxLength)
    {
      buffer.append("    ");
      buffer.append(INDENT);
      buffer.append(description);
      buffer.append(EOL);
    }
    else
    {
      String s = description.toString();
      while (s.length() > 75)
      while (s.length() > descMaxLength)
      {
        int spacePos = s.lastIndexOf(' ', 75);
        int spacePos = s.lastIndexOf(' ', descMaxLength);
        if (spacePos > 0)
        {
          buffer.append("    ");
          buffer.append(INDENT);
          buffer.append(s.substring(0, spacePos).trim());
          s = s.substring(spacePos+1).trim();
          buffer.append(EOL);
@@ -1607,14 +1613,14 @@
          spacePos = s.indexOf(' ');
          if (spacePos > 0)
          {
            buffer.append("    ");
            buffer.append(INDENT);
            buffer.append(s.substring(0, spacePos).trim());
            s = s.substring(spacePos+1).trim();
            buffer.append(EOL);
          }
          else
          {
            buffer.append("    ");
            buffer.append(INDENT);
            buffer.append(s);
            s = "";
            buffer.append(EOL);
@@ -1624,7 +1630,7 @@
      if (s.length() > 0)
      {
        buffer.append("    ");
        buffer.append(INDENT);
        buffer.append(s);
        buffer.append(EOL);
      }
opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
@@ -48,6 +48,7 @@
import java.util.TreeMap;
import org.opends.server.core.DirectoryServer;
import org.opends.server.util.SetupUtils;
@@ -117,6 +118,8 @@
  // The subcommand requested by the user as part of the command-line arguments.
  private SubCommand subCommand;
  private final static String INDENT = "    ";
  private final static int MAX_LENGTH = SetupUtils.isWindows() ? 79 : 80;
  /**
@@ -1435,7 +1438,7 @@
          int lineLength = (buffer.length() - currentLength) +
                           newBuffer.length();
          if (lineLength > 80)
          if (lineLength > MAX_LENGTH)
          {
            buffer.append(EOL);
            buffer.append(newBuffer.toString());
@@ -1474,21 +1477,22 @@
      // indent the description five characters and try our best to wrap at or
      // before column 79 so it will be friendly to 80-column displays.
      Message description = a.getDescription();
      if (description.length() <= 75)
      int maxLength = MAX_LENGTH - INDENT.length() - 1;
      if (description.length() <= maxLength)
      {
        buffer.append("    ");
        buffer.append(INDENT);
        buffer.append(description);
        buffer.append(EOL);
      }
      else
      {
        String s = description.toString();
        while (s.length() > 75)
        while (s.length() > maxLength)
        {
          int spacePos = s.lastIndexOf(' ', 75);
          int spacePos = s.lastIndexOf(' ', maxLength);
          if (spacePos > 0)
          {
            buffer.append("    ");
            buffer.append(INDENT);
            buffer.append(s.substring(0, spacePos).trim());
            s = s.substring(spacePos+1).trim();
            buffer.append(EOL);
@@ -1501,14 +1505,14 @@
            spacePos = s.indexOf(' ');
            if (spacePos > 0)
            {
              buffer.append("    ");
              buffer.append(INDENT);
              buffer.append(s.substring(0, spacePos).trim());
              s = s.substring(spacePos+1).trim();
              buffer.append(EOL);
            }
            else
            {
              buffer.append("    ");
              buffer.append(INDENT);
              buffer.append(s);
              s = "";
              buffer.append(EOL);
@@ -1663,7 +1667,7 @@
    usageOrVersionDisplayed = true;
    if ((toolDescription != null) && (toolDescription.length() > 0))
    {
      buffer.append(wrapText(toolDescription, 79));
      buffer.append(wrapText(toolDescription, MAX_LENGTH - 1));
      buffer.append(EOL);
      buffer.append(EOL);
    }
@@ -1770,7 +1774,7 @@
          Message groupDesc = argGroup.getDescription();
          if (groupDesc != null && !Message.EMPTY.equals(groupDesc)) {
            buffer.append(EOL);
            buffer.append(wrapText(groupDesc.toString(), 79));
            buffer.append(wrapText(groupDesc.toString(), MAX_LENGTH - 1));
            buffer.append(EOL);
            buffer.append(EOL);
          }
@@ -1861,7 +1865,7 @@
    }
    buffer.append(EOL);
    indentAndWrap(Message.raw("    "), a.getDescription(), buffer);
    indentAndWrap(Message.raw(INDENT), a.getDescription(), buffer);
  }
@@ -1874,7 +1878,7 @@
  private void indentAndWrap(Message indent, Message text,
                             MessageBuilder buffer)
  {
    int actualSize = 80 - indent.length();
    int actualSize = MAX_LENGTH - indent.length();
    if (text.length() <= actualSize)
    {
      buffer.append(indent);