commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rob Oxspring <>
Subject [CLI] Options with multiple arguments (was Re: commons cli)
Date Wed, 01 Sep 2004 14:39:05 GMT

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
   // create the print option
   Option print = oBuilder

Hope that helps,


* Unofficial beta available from 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:
> For additional commands, e-mail:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message