commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hezjing <hezj...@gmail.com>
Subject CLI 1.2: HelpFormatter.printHelp()
Date Sat, 18 Apr 2009 05:44:13 GMT
Hi

I have the following program which initially has one option, and print the
usage using HelpFormatter:

OptionBuilder.withDescription("Test
1").withLongOpt("test1").hasArg().isRequired();
 options.addOption(OptionBuilder.create("a"));
HelpFormatter formatter = new HelpFormatter();
 formatter.printHelp(100, "Dummy", null, options, null, true);

The HelpFormatter.printHelp() prints the following:

usage: Dummy -a
 -a,--test1    Test 1

Then, I added the 2nd option (created like the option "a"):

OptionBuilder.withDescription("Test
2").withLongOpt("test2").hasArg().isRequired();
options.addOption(OptionBuilder.create("b"));

and this time the HelpFormatter.printHelp() prints the following:

usage: Dummy -a -b <arg>
  -a,--test1         Test 1
 -b,--test2 <arg>   Test 2

Again, I added the 3rd option (created like the option "a" and "b"):

OptionBuilder.withDescription("Test
3").withLongOpt("test3").hasArg().isRequired();
 options.addOption(OptionBuilder.create("d"));

and the HelpFormatter.printHelp() prints the following:

usage: Dummy -a -b <arg> -d <arg>
 -a,--test1         Test 1
  -b,--test2 <arg>   Test 2
 -d,--test3 <arg>   Test 3


Why doesn't HelpFormatter.printHelp() prints the <arg> for the -a option
while all options are created the same way?
It should print the usage like the following, right?

 usage: Dummy -a -b <arg> -d <arg>
 -a,--test1 <arg>   Test 1
  -b,--test2 <arg>   Test 2
 -d,--test3 <arg>   Test 3


-- 

Hez

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message