[ https://issues.apache.org/jira/browse/CLI-255?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15335882#comment-15335882 ]
Jason Newell commented on CLI-255: ---------------------------------- I've a similar issue but basically DefaultParser doesn't work with a single dash where the option name exceeds one character in length so -a is fine but -ab doesn't work. I've been exercising this with a JUnit test. @Test public void CliTest() throws ArgumentException { s_clsLogger.info("MainWithWrongNumArgsTest()"); try { String strCmk = "xr"; Options s_clsOptions = new Options(); Option clsOptionTstp = Option.builder(strCmk) .valueSeparator('=') .type(String.class) .required() .hasArg() .argName("TestCommandPath=value") .desc("A test path") .build(); s_clsOptions.addOption(clsOptionTstp); String[] astrCli = new String[]{String.format("-%s=cd", strCmk)}; CommandLineParser s_clsClParser = new DefaultParser(); CommandLine clsCommandLine = s_clsClParser.parse(s_clsOptions, astrCli, true); if(clsCommandLine.hasOption(strCmk)) { String strOptionValue = clsCommandLine.getOptionValue(strCmk); assertEquals(strOptionValue,"cd"); } else { fail(); } } catch (Exception e) { s_clsLogger.error(e); fail(e.toString()); } finally { } } > DefaultParser, option with long name and single dash, unlimited arguments > ------------------------------------------------------------------------- > > Key: CLI-255 > URL: https://issues.apache.org/jira/browse/CLI-255 > Project: Commons CLI > Issue Type: Bug > Components: Parser > Affects Versions: 1.3, 1.3.1 > Reporter: Alexander Prishchepov > Priority: Minor > > If I have options with long name and single dash, DefaultParser does not > recognize them after a list of unlimited arguments. > Here is the test case: > {code:java} > 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); > } > {code} -- This message was sent by Atlassian JIRA (v6.3.4#6332)