You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Maximilian Haeussler <ma...@gmx.de> on 2004/08/31 13:29:56 UTC

commons cli

Hallo,

I couldn't find a mainling list for commons cli. Therefore I'm sending 
the question to you: How can I build an option with multiple arguments??
And how do I later retreive the values? I don't understand the 
sourcecode sufficiently. Apart from that, when i set .hasArgs(2) for an 
option built by the optionbuilder, helpformatter doesn't reflect this in 
any way, only the last option is printed in the help text.

I want something like "-print <textfile> <linelength>" but this is far 
from obvious after having read the documentation.

I don't want to introduce an new option "-print <textfile> -linelength 
<number>" as -linelength applies only to the "-print" option and to no 
other options.

Thanks!

Max


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: [CLI] Options with multiple arguments (was Re: commons cli)

Posted by max haeussler <ma...@web.de>.
Hi Rob,

hey thanks for your long reply, I really didn't expect that at the
moment...anyways, I'm using cli 1 now, simply doing the check myself. It's
not nice, neither anything close to good design, but it works for the
moment. As soon as the things break up, when I'm adding more options (as
usual...) I will try out the code you sent me. At the moment, I'm just glad
everything starts up and keeps going for a while...

Max
----- Original Message ----- 
From: "Rob Oxspring" <ro...@imapmail.org>
To: "Jakarta Commons Users List" <co...@jakarta.apache.org>
Sent: Wednesday, September 01, 2004 10:39 PM
Subject: [CLI] Options with multiple arguments (was Re: commons cli)


> Hi,
>
> This is the right list :)
>
> I can't think of anyway to tackle this with CLI1, and the problem wasn't
> considered when designing CLI2 either.  However you should be able to
> work around things if your willing to try a CLI2 snapshot.*
>
> CLI2 is still limitted to having a single argument per option but does
> allow 'child' options.  A -linelength child option would only be valid
> following a -print option and both the child and parent would have an
> argument, the output of HelpFormatter tries to make this relationship
> clear to the user.  I would recommend this solution as it allows for
> easier future expansion (-justify?, -margin?) but the following work
> around should get you closer to the desired result:
>
>    // not tested but it should give you a starting point
>
>    // grab some builders
>    ArgumentBuilder aBuilder = new ArgumentBuilder();
>    GroupBuilder gBuilder = new GroupBuilder();
>    DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();
>
>    // build the two arguments
>    Argument textfile = aBuilder.withName("textfile").create();
>    Argument linelength = aBuilder.withName("linelength").create();
>    // create a group containing those arguments
>    Group children = gBuilder
>        .withOption(textfile)
>        .withOption(linelength)
>        .create();
>    // create the print option
>    Option print = oBuilder
>        .withShortName("print")
>        .withChildren(args)
>        .create();
>
> Hope that helps,
>
> Rob
>
> * Unofficial beta available from
> http://www.apache.org/~roxspring/cli/distributions/ until I sort out the
> official one.
>
> Maximilian Haeussler wrote:
>
> > Hallo,
> >
> > I couldn't find a mainling list for commons cli. Therefore I'm sending
> > the question to you: How can I build an option with multiple arguments??
> > And how do I later retreive the values? I don't understand the
> > sourcecode sufficiently. Apart from that, when i set .hasArgs(2) for an
> > option built by the optionbuilder, helpformatter doesn't reflect this in
> > any way, only the last option is printed in the help text.
> >
> > I want something like "-print <textfile> <linelength>" but this is far
> > from obvious after having read the documentation.
> >
> > I don't want to introduce an new option "-print <textfile> -linelength
> > <number>" as -linelength applies only to the "-print" option and to no
> > other options.
> >
> > Thanks!
> >
> > Max
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-user-help@jakarta.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


[CLI] Options with multiple arguments (was Re: commons cli)

Posted by Rob Oxspring <ro...@imapmail.org>.
Hi,

This is the right list :)

I can't think of anyway to tackle this with CLI1, and the problem wasn't 
considered when designing CLI2 either.  However you should be able to 
work around things if your willing to try a CLI2 snapshot.*

CLI2 is still limitted to having a single argument per option but does 
allow 'child' options.  A -linelength child option would only be valid 
following a -print option and both the child and parent would have an 
argument, the output of HelpFormatter tries to make this relationship 
clear to the user.  I would recommend this solution as it allows for 
easier future expansion (-justify?, -margin?) but the following work 
around should get you closer to the desired result:

   // not tested but it should give you a starting point

   // grab some builders
   ArgumentBuilder aBuilder = new ArgumentBuilder();
   GroupBuilder gBuilder = new GroupBuilder();
   DefaultOptionBuilder oBuilder = new DefaultOptionBuilder();

   // build the two arguments
   Argument textfile = aBuilder.withName("textfile").create();
   Argument linelength = aBuilder.withName("linelength").create();
   // create a group containing those arguments
   Group children = gBuilder
       .withOption(textfile)
       .withOption(linelength)
       .create();
   // create the print option
   Option print = oBuilder
       .withShortName("print")
       .withChildren(args)
       .create();

Hope that helps,

Rob

* Unofficial beta available from 
http://www.apache.org/~roxspring/cli/distributions/ until I sort out the 
official one.

Maximilian Haeussler wrote:

> Hallo,
> 
> I couldn't find a mainling list for commons cli. Therefore I'm sending 
> the question to you: How can I build an option with multiple arguments??
> And how do I later retreive the values? I don't understand the 
> sourcecode sufficiently. Apart from that, when i set .hasArgs(2) for an 
> option built by the optionbuilder, helpformatter doesn't reflect this in 
> any way, only the last option is printed in the help text.
> 
> I want something like "-print <textfile> <linelength>" but this is far 
> from obvious after having read the documentation.
> 
> I don't want to introduce an new option "-print <textfile> -linelength 
> <number>" as -linelength applies only to the "-print" option and to no 
> other options.
> 
> Thanks!
> 
> Max
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org