commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pierre-Luc Lacroix (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CLI-246) GnuParser removes first character from longer argument containing single character option
Date Tue, 16 Sep 2014 14:25:33 GMT
Pierre-Luc Lacroix created CLI-246:
--------------------------------------

             Summary: GnuParser removes first character from longer argument containing single
character option
                 Key: CLI-246
                 URL: https://issues.apache.org/jira/browse/CLI-246
             Project: Commons CLI
          Issue Type: Bug
          Components: CLI-1.x
    Affects Versions: 1.2
         Environment: Windows 64-bit
            Reporter: Pierre-Luc Lacroix
            Priority: Minor


Title might be hard to understand, but basically:

Arguments:
String [] cli = {"-cc", "-ccc", "-c"};

Options:
Options opts = new Options();
opts.addOption(OptionBuilder.create("cc"));
opts.addOption(OptionBuilder.create("c"));

As you can see, "-ccc" is an extra unrecognized argument.

When you try to parse it:

CommandLineParser parser = new GnuParser();
CommandLine line = parser.parse(opts, cli, true);


Content on line:
args: [cc, -c]
line: [[ option: cc  :: null ], [ option: c  :: null ]]

I would expect:
args: [-ccc]
line: [[ option: cc  :: null ], [ option: c  :: null ]]


Wrote a little unit test (that fails):

{code:title=UnitTest.java|borderStyle=solid}
	@Test
	public void test3() throws ParseException {
		
		String [] cli = {"-cc", "-ccc", "-c"};
		
		Options opts = new Options();
		opts.addOption(OptionBuilder.create("cc"));
		opts.addOption(OptionBuilder.create("c"));
		
		CommandLineParser parser = new GnuParser();
		CommandLine line = parser.parse(opts, cli, true);
		
		if (line.getArgs().length > 0 ) {
			Assert.assertEquals("-ccc", line.getArgList().get(0));
		}

	}
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message