commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <>
Subject Re: [CLI] CLI Validation - Was: WELCOME to
Date Thu, 16 Aug 2007 08:14:22 GMT
Brian A. Egge wrote:
> Hi Wolfgang,
> I agree that the framework should have better support for groups and mutually exclusive
options.  This is a feature I've often had to do in a pre or post processing step.  
> I've thought about writing a CLI library which would accept a EBNF option grammar, much
like JavaCC or ANTLR.  You could do the validation, and assign actions to options or commands.
 A simple grammar would be easier to specify the arguments than a *Builder object.  Realistically,
though, I know I don't have the time to take on such a project, so my best bet it to improve
on one of the existing projects.
> I should have some time in the next few weeks to get some fixes into CLI 2.x, and look
at ways of making it do smarter validation.
> -Brian

A grammer is certainly a precise and compact way of defining the allowed
command line arguments, but in can also become quite complex. I assume
the average user of a CLI library is not used to thinking this way.

How about defining a set of extensible rules, which describe the
supported arguments? There could be default rules like
- parameter foo must have one of these values (a, b, c)
- if parameter foo is present, bar must not be present
- an existing file must be specified

If the default rules are not enough for defining a complex parameter
interface, custom rules could be defined. The rules could be either
defined using a builder-like approach or read from some kind of
definition file.

This sounds a bit like Digester, doesn't it? And indeed using such a
library could look as follows:
- An application object is passed to CLI.
- CLI processes the command line arguments based on the specified rules.
- Setter methods on the application object are invoked with the
identified command line options.

This would be easy and convenient to use, but if the interface of the
rules is carefully designed, very flexible.

My $0.02

> Wolfgang Roessler <> wrote: Hi Hen,
> the Commons Validator package sounds interesting and I perhaps it should 
> be possible to use these validators. But I also like the CLI2 validators 
> for files and directories. The validators I am missing are something 
> like dependency-validators, e.g. specify mutually exclusive options. 
> Groups offer very little support for this.
> Currently validation and parsing is mixed up I think. This way if I pass 
> a filename and the file should be writable but it isn't, I get an error 
> that the option is missing and not, that there is a problem with the 
> specified file. Perhaps this should be separated in a FileOption and the 
> validator.
> In my opinion the target of CLI2 should be, that all parsing and 
> validation is performed by the framework.
> Wolfgang

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

View raw message