Commons CLI
  1. Commons CLI
  2. CLI-179

Needs "standalone" options that can be used even if required options are not set

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2
    • Fix Version/s: 1.4
    • Component/s: Parser
    • Labels:
      None

      Description

      it is currently impossible to have options like "help" or "version" if we also have some required options. The parsing results in an error "Missing parameters".

      But for an "help" or "version" option, it would be usefull to display the wanted information, even if required options are not set.

      1. CLI-179.patch
        7 kB
        Jacopo Cappellato

        Issue Links

          Activity

          Hide
          Emmanuel Bourg added a comment -

          Good point. But I don't know how this could be implemented. I see how one could work around this issue, either:

          • drop the required flag on the options
          • perform a two pass parsing with different options: the first one to detect a "standalone" option, the second one to parse all the options allowed

          Suggestions are welcome.

          Show
          Emmanuel Bourg added a comment - Good point. But I don't know how this could be implemented. I see how one could work around this issue, either: drop the required flag on the options perform a two pass parsing with different options: the first one to detect a "standalone" option, the second one to parse all the options allowed Suggestions are welcome.
          Hide
          Joël Royer added a comment -

          I suggest adding a method isStandalone (true/false) to the OptionBuilder class.
          The parser would authorize the use of standalone options without required options.

          Show
          Joël Royer added a comment - I suggest adding a method isStandalone (true/false) to the OptionBuilder class. The parser would authorize the use of standalone options without required options.
          Hide
          Emmanuel Bourg added a comment -

          Actually there is a solution with the current API. You can create a group with --version, --help and your options, and mark it as required. The parser will check if one of the options is present.

          Show
          Emmanuel Bourg added a comment - Actually there is a solution with the current API. You can create a group with --version, --help and your options, and mark it as required. The parser will check if one of the options is present.
          Hide
          Michael Heuer added a comment - - edited

          This appears to be the same problem I posted about to commons-user earlier. I will give your workaround a try, Emmanuel.

          http://mail-archives.apache.org/mod_mbox/commons-user/200903.mbox/%3CPine.GSO.4.44.0903121240051.16891-100000@shell3.shore.net%3E

          Show
          Michael Heuer added a comment - - edited This appears to be the same problem I posted about to commons-user earlier. I will give your workaround a try, Emmanuel. http://mail-archives.apache.org/mod_mbox/commons-user/200903.mbox/%3CPine.GSO.4.44.0903121240051.16891-100000@shell3.shore.net%3E
          Hide
          Michael Scheper added a comment -

          Not sure the group solution is a real solution. When I try it, it makes the HelpFormatter output strange, and it adds a level of complexity to retrieving the option. +1 on Joël Royer's isStandalone(boolean) suggestion.

          Show
          Michael Scheper added a comment - Not sure the group solution is a real solution. When I try it, it makes the HelpFormatter output strange, and it adds a level of complexity to retrieving the option. +1 on Joël Royer 's isStandalone(boolean) suggestion.
          Hide
          Jacopo Cappellato added a comment -

          This is my attempt to implement "standalone" options for the new Option.builder() and DefaultParser.
          It would be great if someone with more knowledge of the CLI codebase than me could review it, possibly test and let me know if this is the right approach. The JavaDoc comments should be enhanced too.

          Show
          Jacopo Cappellato added a comment - This is my attempt to implement "standalone" options for the new Option.builder() and DefaultParser. It would be great if someone with more knowledge of the CLI codebase than me could review it, possibly test and let me know if this is the right approach. The JavaDoc comments should be enhanced too.

            People

            • Assignee:
              Unassigned
              Reporter:
              Joël Royer
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:

                Development