You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by hezjing <he...@gmail.com> on 2009/04/18 07:44:13 UTC

CLI 1.2: HelpFormatter.printHelp()

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