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

DefaultParser, option with long name and single dash, unlimited arguments

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.3, 1.3.1
    • None
    • Parser
    • None

    Description

      If I have options with long name and single hyphen, DefaultParser does not recognize them after a list of unlimited arguments.
      Here is the test case:

          public void testUnlimitedArgs() throws Exception
          {
              String[] args = new String[] {"-unlimitedOne", "one", "two", "-unlimitedTwo", "alpha"};
      
              Options options = new Options();
              options.addOption(Option.builder("unlimitedOne").hasArgs().build());
              options.addOption(Option.builder("unlimitedTwo").hasArgs().build());
      
              CommandLine cl = parser.parse(options, args);
      
              assertTrue("Confirm -unlimitedOne is set", cl.hasOption("unlimitedOne"));
              assertEquals("number of arg for -unlimitedOne", 2, cl.getOptionValues("unlimitedOne").length);
              assertTrue("Confirm -unlimitedTwo is set", cl.hasOption("unlimitedTwo"));
              assertEquals("number of arg for -unlimitedTwo", 1, cl.getOptionValues("unlimitedTwo").length);
          }
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            sans17 Alexander Prishchepov
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated: