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

HelpFormatter#setOptionComparator(null) doesn't display the values in inserted order

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.3.1
    • Fix Version/s: 1.4
    • Component/s: CLI-1.x, Help formatter
    • Labels:
    • Environment:

      Windows

      Description

      OptionGroup group = new OptionGroup();
      Option h = Option.builder("h").build();
      Option s = Option.builder("s").build();
      Option b = Option.builder("b").build();
      Option t = Option.builder("t").build();
      group.addOption(h)
          .addOption(s)
          .addOption(b)
          .addOption(t);
      Options options = new Options();
      options.addOptionGroup(group);
      options.addOption(Option.builder("o").build());
      HelpFormatter formatter = new HelpFormatter();
      formatter.setOptionComparator(null);
      formatter.printHelp("cmd", "", options, null);
      

      This code does print the options(1. Group, 2. Option "o") in the order of insertion but the groups order of display is messed up.

      The OptionGroup internally uses a HashMap. If that could be replaced with a LinkedHashMap this issue can be solved.

        Issue Links

          Activity

          Hide
          garydgregory Gary Gregory added a comment -

          Would you be willing to provide a patch with unit tests?

          Show
          garydgregory Gary Gregory added a comment - Would you be willing to provide a patch with unit tests?
          Hide
          bond_ Raviteja Lokineni added a comment -

          Gary Gregory I'm planning to. I will try to get it done this weekend.

          Show
          bond_ Raviteja Lokineni added a comment - Gary Gregory I'm planning to. I will try to get it done this weekend.
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user bond- opened a pull request:

          https://github.com/apache/commons-cli/pull/6

          CLI-266: HelpFormatter with comparator null now displays in the inserted order

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/bond-/commons-cli trunk

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/commons-cli/pull/6.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #6


          commit bc7bba7b03ca51a43810bb2eb9c29e3028bac23c
          Author: Raviteja Lokineni <bond-@users.noreply.github.com>
          Date: 2016-06-21T20:06:10Z

          CLI-266: HelpFormatter#setOptionComparator(null) now displays in the inserted order


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user bond- opened a pull request: https://github.com/apache/commons-cli/pull/6 CLI-266 : HelpFormatter with comparator null now displays in the inserted order You can merge this pull request into a Git repository by running: $ git pull https://github.com/bond-/commons-cli trunk Alternatively you can review and apply these changes as the patch at: https://github.com/apache/commons-cli/pull/6.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #6 commit bc7bba7b03ca51a43810bb2eb9c29e3028bac23c Author: Raviteja Lokineni <bond-@users.noreply.github.com> Date: 2016-06-21T20:06:10Z CLI-266 : HelpFormatter#setOptionComparator(null) now displays in the inserted order
          Hide
          bond_ Raviteja Lokineni added a comment -

          Gary Gregory Created a pull request. Please review: https://github.com/apache/commons-cli/pull/6

          Show
          bond_ Raviteja Lokineni added a comment - Gary Gregory Created a pull request. Please review: https://github.com/apache/commons-cli/pull/6
          Hide
          britter Benedikt Ritter added a comment -
          $ svn ci -m "CLI-266: HelpFormatter.setOptionComparator(null) doesn't display the values in inserted order. Thank you to Ravi Teja. This also closes #6 from GitHub."
          Sending        src/changes/changes.xml
          Sending        src/main/java/org/apache/commons/cli/OptionGroup.java
          Sending        src/main/java/org/apache/commons/cli/Options.java
          Adding         src/test/java/org/apache/commons/cli/bug/BugCLI266Test.java
          Transmitting file data ....done
          Committing transaction...
          Committed revision 1749596.
          

          Thank you!

          Show
          britter Benedikt Ritter added a comment - $ svn ci -m "CLI-266: HelpFormatter.setOptionComparator( null ) doesn't display the values in inserted order. Thank you to Ravi Teja. This also closes #6 from GitHub." Sending src/changes/changes.xml Sending src/main/java/org/apache/commons/cli/OptionGroup.java Sending src/main/java/org/apache/commons/cli/Options.java Adding src/test/java/org/apache/commons/cli/bug/BugCLI266Test.java Transmitting file data ....done Committing transaction... Committed revision 1749596. Thank you!
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/commons-cli/pull/6

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/commons-cli/pull/6

            People

            • Assignee:
              britter Benedikt Ritter
              Reporter:
              bond_ Raviteja Lokineni
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development