commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Miguel Muñoz <>
Subject Re: [CLI] Required and Optional Groups
Date Thu, 27 Jul 2006 18:44:12 GMT

Thank you for the suggestion, but it didn't work. Although some of  
the info in my post was wrong. I claimed I was getting this:

       ShellCommand [-DB|-SCM|-SCW] [-s <source>]

I was actually getting this:

       ShellCommand [-DB|-SCM|-SCW -s <source>]

What I want hasn't changed:

       ShellCommand -DB|-SCM|-SCW [-s <source>]

Adding setMinimum(1) and setMaximum(1) to the initial group didn't  
change anything.

I have no idea what I'm doing wrong.

If you're interested, here's my code.

	private static void processArgs() {
		DefaultOptionBuilder oBldr = new DefaultOptionBuilder();
		Option dbOption = oBldr
						.withDescription("DB Project")
		Option scMacOption = oBldr
						.withDescription("SC for Mac Project")
		Option scWinOption = oBldr
						.withDescription("SC for Windows Project")
		GroupBuilder gb = new GroupBuilder();
		Group project = gb
						.withDescription("Specifies the Project")

		ArgumentBuilder aBldr = new ArgumentBuilder();
		Argument srcArg = aBldr.withName("source")
		Option compatible = oBldr.withShortName("s")
						.withDescription("Use Source")
		Group all = gb.withOption(project).withOption(compatible).create();

		HelpFormatter fmt = new HelpFormatter();


On Jul 27, 2006, at 4:25 AM, Andrew Shirley wrote:

> On Wed, Jul 26, 2006 at 10:06:09PM -0700, Miguel Muñoz wrote:
>> Comrades,
>>   I want to use CLI 2.0 to create command line options that look  
>> like this:
>> ShellCommand -DB|-SCM|-SCW [-s <source>]
>> I'm adding three DefaultOptions to a group to get the first set (- 
>> DB|-SCM|-SCW), but the trouble is, the user is required to specify  
>> one of
>> the three, but I can't figure out a way to make this group  
>> required. Consequently, I'm getting this:
>> ShellCommand [-DB|-SCM|-SCW] [-s <source>]
>> This is not what I want.
>> Is there any way to do this?
> hi, you should be able to set a minimum number of children needed to
> satisfy the group i.e. 1 in this case. This can be done in the
> constructor of GroupImpl or if you are using the GroupBuilder
> (recommended) then call .withMinimum(1) before .create()
> If they have to specify exactly 1, then you will need .withMaximum(1)
> as well, otherwise "-DB -SCM -s foo" would be accepted.
> hope this helps
> Andrew Shirley
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:


Miguel Muñoz


The Sun, with all those planets revolving around it and dependent on  
it, can still ripen a vine of grapes like it had nothing else to do  
in the world.

   -- Galileo


There are seven sins in the world.
     Wealth without work.
     Pleasure without conscience.
     Knowledge without character.
     Commerce without morality.
     Science without humanity.
     Worship without sacrifice.
     Politics without principle.

   -- Mohandas Gandhi


If tyranny and oppression come to this land, it will come in the  
guise of fighting a foreign enemy.

   -- James Madison

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