You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Miguel Muñoz <Sw...@yahoo.com> on 2006/07/27 07:06:09 UTC
[CLI] Required and Optional Groups
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?
For backwards compatibility with previous tools, I don't want to get
rid of the dash on these options if I don't have to.
-- Miguel Muñoz
___________________
There are 10 kinds of people: Those who know binary and those who don't.
Re: [CLI] Required and Optional Groups
Posted by Miguel Muñoz <Sw...@yahoo.com>.
Andrew,
Food for thought: I'm not sure if this is contained in your recent
bug reports on this problem, but there seems to be a second issue
here that should be addressed. In the example below, the DB/SCM/SCW
is in one group, and the -s is in a different group, but they're
displayed with a single set of square brackets around them. as in
line 2 below: It seems to me that this is also a bug. The child group
should get its own set of square brackets, as in line 1 below.
Was this also reflected in your two recent bug reports?
-- Miguel
On Jul 28, 2006, at 2:45 AM, Andrew Shirley wrote:
> On Thu, Jul 27, 2006 at 11:44:12AM -0700, Miguel Muñoz wrote:
>> Andrew,
>>
>> 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>] // line 1
>>
>> I was actually getting this:
>>
>> ShellCommand [-DB|-SCM|-SCW -s <source>] // line 2
>>
>> What I want hasn't changed:
>>
>> ShellCommand -DB|-SCM|-SCW [-s <source>]
>
> The problem is that the 'all' group is has a minimum of 0 and so gets
> square-bracketed. This is incorrect as we know that project group is
> required and so we will have to have at least one argument. I'm not
> really sure of a way to solve this, I think we will have to improve
> the
> concept of when a group is optional. It will validate the arguments
> correctly and it is just the HelpFormatter which is incorrect. As an
> aside, I found that Groups aren't counted in thw minimum/maximum count
> and I think this is wrong as if they were counted, you could give it a
> hint by saying that all has a minimum of 1 (the project group) however
> as it stands, this would make -s required. I will file a bug about
> these
> things shortly.
>
> Sorry this wasn't more helpful.
>
> Andrew Shirley
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
-------------------------------------------
Miguel Muñoz
SwingGuy1024@yahoo.com
323/225-7285
-------------------------------------------
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
Re: [CLI] Required and Optional Groups
Posted by Miguel Muñoz <Sw...@yahoo.com>.
Andrew,
Thanks for clearing this up somewhat. It seems to me that if the
command line gets parsed correctly, the help formatter should be able
to display it correctly using the same kind of mechanism.
-- MM
On Jul 28, 2006, at 2:45 AM, Andrew Shirley wrote:
> On Thu, Jul 27, 2006 at 11:44:12AM -0700, Miguel Muñoz wrote:
>> Andrew,
>>
>> 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>]
>
> The problem is that the 'all' group is has a minimum of 0 and so gets
> square-bracketed. This is incorrect as we know that project group is
> required and so we will have to have at least one argument. I'm not
> really sure of a way to solve this, I think we will have to improve
> the
> concept of when a group is optional. It will validate the arguments
> correctly and it is just the HelpFormatter which is incorrect. As an
> aside, I found that Groups aren't counted in thw minimum/maximum count
> and I think this is wrong as if they were counted, you could give it a
> hint by saying that all has a minimum of 1 (the project group) however
> as it stands, this would make -s required. I will file a bug about
> these
> things shortly.
>
> Sorry this wasn't more helpful.
>
> Andrew Shirley
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
-------------------------------------------
Miguel Muñoz
SwingGuy1024@yahoo.com
323/225-7285
-------------------------------------------
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
Re: [CLI] Required and Optional Groups
Posted by Andrew Shirley <ak...@decisionsoft.co.uk>.
On Thu, Jul 27, 2006 at 11:44:12AM -0700, Miguel Muñoz wrote:
> Andrew,
>
> 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>]
The problem is that the 'all' group is has a minimum of 0 and so gets
square-bracketed. This is incorrect as we know that project group is
required and so we will have to have at least one argument. I'm not
really sure of a way to solve this, I think we will have to improve the
concept of when a group is optional. It will validate the arguments
correctly and it is just the HelpFormatter which is incorrect. As an
aside, I found that Groups aren't counted in thw minimum/maximum count
and I think this is wrong as if they were counted, you could give it a
hint by saying that all has a minimum of 1 (the project group) however
as it stands, this would make -s required. I will file a bug about these
things shortly.
Sorry this wasn't more helpful.
Andrew Shirley
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [CLI] Required and Optional Groups
Posted by Miguel Muñoz <Sw...@yahoo.com>.
Andrew,
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
.withShortName("DB")
.withDescription("DB Project")
.create();
Option scMacOption = oBldr
.withShortName("SCM")
.withDescription("SC for Mac Project")
.create();
Option scWinOption = oBldr
.withShortName("SCW")
.withDescription("SC for Windows Project")
.create();
GroupBuilder gb = new GroupBuilder();
Group project = gb
.withName("Project")
.withDescription("Specifies the Project")
.withOption(dbOption)
.withOption(scMacOption)
.withOption(scWinOption)
.withMinimum(1)
.withMaximum(1)
.create();
ArgumentBuilder aBldr = new ArgumentBuilder();
Argument srcArg = aBldr.withName("source")
.withMinimum(1)
.withMaximum(1)
.create();
Option compatible = oBldr.withShortName("s")
.withShortName("source")
.withDescription("Use Source")
.withRequired(false)
.withArgument(srcArg)
.create();
Group all = gb.withOption(project).withOption(compatible).create();
HelpFormatter fmt = new HelpFormatter();
fmt.setGroup(all);
fmt.setShellCommand("ShellCommand");
fmt.print();
}
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: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
-------------------------------------------
Miguel Muñoz
SwingGuy1024@yahoo.com
323/225-7285
-------------------------------------------
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
Re: [CLI] Required and Optional Groups
Posted by Andrew Shirley <ak...@decisionsoft.co.uk>.
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: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org