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.

        Attachments

          Issue Links

            Activity

              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: