Uploaded image for project: 'Commons CLI'
  1. Commons CLI
  2. CLI-15

HelpFormatter does not handle groups properly

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0
    • 1.1
    • Help formatter
    • None
    • 19749

    Description

      The HelpFormatter repeats Options that have previously been printed with the group.

      The problem is in the else block where options not belonging to a group are
      printed. The code gets executed if it does not belong to a group OR if the
      group has already been printed.

      if( group != null && !list.contains(group)) {
      // this gets executed when a new group is found
      ...
      } else

      { // this gets executed if the group is OR ISN'T null, and if group is in list. .... } The else statement on line 267 should be as follows: }

      else if (group == null) {
      // This will make sure that options that have not been printed as part of a group
      // will not get printed again.
      ...
      }

      I believe this change fixes the problem.

      Also, the append on line 264 should add an extra space after the ] to make sure
      that there will be a space between the ] and the next option.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--Option.java
          18 kB
          Etienne Pelletier
        2. ASF.LICENSE.NOT.GRANTED--HelpFormatter.java
          18 kB
          Etienne Pelletier

        Activity

          People

            Unassigned Unassigned
            etienne.pelletier@pegs.com Etienne Pelletier
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: