Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: 1.3
    • Component/s: Help formatter
    • Labels:
      None

      Description

      The HelpFormatter always renders a space between the option name and value even if the option has a value separator that is not a space. For example, this option:

      Option option = new Option("B", "bsize", true, "block size in bytes");
      option.setArgName("SIZE");
      option.setValueSeparator('=');
      

      is rendered like this:

      -B,--bsize <SIZE>  block size in bytes
      

      But I would expect it to be rendered like this:

      -B,--bsize=<SIZE>  block size in bytes
      

      For the automatically generated usage message, a similar problem exists. I changed it to try to use the value separator when rendering the option with the short name only if there's no long name. If there's no short name, it always tries to use the value separator with the long name rendering.

      For example, consider this option containing a short name and a specified value separator:

      Option option = new Option("B", true, "block size in bytes");
      option.setArgName("SIZE");
      option.setValueSeparator('=');
      

      The automatically generated usage message with my changes would look like this:

      usage: app [-B=<SIZE>]
      

      If the same option included a long name too:

      Option option = new Option("B", "bsize", true, "block size in bytes");
      option.setArgName("SIZE");
      option.setValueSeparator('=');
      

      with my changes the value separator is assumed to be meant for use with the long name. The short option rendering in the usage message will not try to use the value separator and will render the usage message like this:

      usage: app [-B <SIZE>]
      

      Attached is a patch for these fixes with test cases. The patch is against http://svn.apache.org/repos/asf/commons/proper/cli/branches/cli-1.x.

      1. use-value-separator-in-help-formatter.patch
        10 kB
        J. Lewis Muir
      2. long-opt-name-arg-separator.patch
        10 kB
        J. Lewis Muir
      3. use-equal-sign-with-long-opts.patch
        10 kB
        J. Lewis Muir

        Activity

          People

          • Assignee:
            Unassigned
            Reporter:
            J. Lewis Muir
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Time Tracking

              Estimated:
              Original Estimate - 0.5h
              0.5h
              Remaining:
              Remaining Estimate - 0.5h
              0.5h
              Logged:
              Time Spent - Not Specified
              Not Specified

                Development