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

[cli] CommandLine.getOptionValue() behaves contrary to docs

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.1
    • Component/s: CLI-1.x
    • Labels:
      None
    • Environment:

      Operating System: Linux
      Platform: PC

    • Bugzilla Id:
      36997

      Description

      Hi

      If I have:

      final String debugOpt = "debug";
      Option debug = OptionBuilder
      .withArgName(debugOpt)
      .withDescription("turn on debugging")
      .withLongOpt(debugOpt)
      .create('d');

      and then later I do:

      String dbg = commandLine.getOptionValue(debugOpt);

      then dbg will be null. Instead, I have to use getOptionValue('d'). This seems
      contrary to the docs (see bottom of
      http://jakarta.apache.org/commons/cli/usage.html), which implies that I should
      be able to query the commandLine object using a full string, rather than just
      the string's first character.

      Can I suggest that the API of OptionBuilder be made clearer so that it is
      obvious that you can have long and short option names---perhaps make the
      create() method take no arguments (thus forcing long and short arg names to be
      set explicitly). (Also, there seems to be some confusion between the terms
      'argument' and 'option' in the API, but perhaps that is just me).

      Also, I would hop to be able to query commandLine by either a single char or an
      entire string, as suggested by the docs.

      Thanks,

      Chris

      1. CL13.patch
        6 kB
        Brian Egge

        Activity

        Hide
        aks Andrew Shirley added a comment -

        moving this forward to cli2, you can use CommandLine#getValue(String) with "d" or "-debug" so this is fixed in cli2. I havn't looked at this problem in cli1

        Show
        aks Andrew Shirley added a comment - moving this forward to cli2, you can use CommandLine#getValue(String) with " d" or " -debug" so this is fixed in cli2. I havn't looked at this problem in cli1
        Hide
        bayard Henri Yandell added a comment -

        Setting a fix version of 1.1 - however there's nothing to say a 1.1 release will happen. It sounds like the CLI 2 API is much preferred and likely to have lots more attention.

        Show
        bayard Henri Yandell added a comment - Setting a fix version of 1.1 - however there's nothing to say a 1.1 release will happen. It sounds like the CLI 2 API is much preferred and likely to have lots more attention.
        Hide
        brianegge Brian Egge added a comment -

        Implemented hashCode and equals in the Option class, so CommandLine can just keep a set of the options. Allow for looking up option with either the short or long option.

        Show
        brianegge Brian Egge added a comment - Implemented hashCode and equals in the Option class, so CommandLine can just keep a set of the options. Allow for looking up option with either the short or long option.
        Hide
        bayard Henri Yandell added a comment -

        On the suggestion, API changes should be avoided in CLI1 - better to look at CLI2 and consider them there.

        If an easy change, then querying commandLine might be worth a look, but probably not.

        Unit test and fix patch applied. Thanks Brian! Great to have movement in CLI again.

        Show
        bayard Henri Yandell added a comment - On the suggestion, API changes should be avoided in CLI1 - better to look at CLI2 and consider them there. If an easy change, then querying commandLine might be worth a look, but probably not. Unit test and fix patch applied. Thanks Brian! Great to have movement in CLI again.

          People

          • Assignee:
            Unassigned
            Reporter:
            junk5@microserf.org.uk C Rose
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development