You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Henri Yandell <fl...@gmail.com> on 2006/09/10 09:37:39 UTC
[cli][configuration][convert] Architecting our overlaps
So I'm using [cli] in [finder] to see if I can mimic the command line
interface for the unix find command. I'm using the cli2 version - lots
of thought, but very painful to use. Here are the 30 lines of code to
add a single option:
<code>
public static void main(String[] args) throws OptionException {
DefaultOptionBuilder obuilder = new DefaultOptionBuilder();
ArgumentBuilder abuilder = new ArgumentBuilder();
GroupBuilder gbuilder = new GroupBuilder();
Option type =
obuilder
.withShortName("type")
.withDescription("True if the file is of the specified type.")
.withArgument(
abuilder
.withName("type-flag")
.withMinimum(1)
.withMaximum(1)
.create()
)
.create();
Group options =
gbuilder
.withName("options")
.withOption(type)
.create();
Parser parser = new Parser();
parser.setGroup(options);
CommandLine cl = parser.parse(args);
if(cl.hasOption(type)) {
System.out.println("USE TYPE: " + cl.getValue(type));
}
}
</code>
Obviously a second flag wouldn't double it or anything, but it's still
a lot. So my first thought is wondering how the API can be simpler for
simple cases. Power is good, power when it's not needed is
unmanageable.
Perusing the CLI2 javadoc, my second thought is that it overlaps with
Configuration a lot. You can have Properties and Preferences command
lines; and Configuration lacks a CLI style way to input data.
A third thought is that the CLI2 CommandLine API for the data itself
rests on a getValue(Option);Object method, which implies some
conversion is going on but I've not seen how yet by looking at the
API. Configuration also does conversion of String to various objects.
BeanUtils does that too, which gave rise to an overmodelled [convert]
package that we've talked about restarting as something simpler.
--
Any of that kick off any thoughts?
Hen
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [cli][configuration][convert] Architecting our overlaps
Posted by Oliver Heger <ol...@oliver-heger.de>.
Henri Yandell wrote:
> So I'm using [cli] in [finder] to see if I can mimic the command line
> interface for the unix find command. I'm using the cli2 version - lots
> of thought, but very painful to use. Here are the 30 lines of code to
> add a single option:
<snip/>
Must learn more about the CLI API before I can comment on this.
>
> Perusing the CLI2 javadoc, my second thought is that it overlaps with
> Configuration a lot. You can have Properties and Preferences command
There is an enhancement request for [configuration] for a command line
configuration: http://issues.apache.org/jira/browse/CONFIGURATION-211
This also shows that there is overlap.
> lines; and Configuration lacks a CLI style way to input data.
Not sure what you mean by this.
>
> A third thought is that the CLI2 CommandLine API for the data itself
> rests on a getValue(Option);Object method, which implies some
> conversion is going on but I've not seen how yet by looking at the
> API. Configuration also does conversion of String to various objects.
> BeanUtils does that too, which gave rise to an overmodelled [convert]
> package that we've talked about restarting as something simpler.
In [configuration] there are many conversion functions to different data
types. Especially the conversions that deal with arrays and lists are a
pain IMHO: There is a huge amount of code that implements these
conversions in a structural very similar way. It would be really cool
(except for an additional dependency) if this code could be dropped or
significantly be simplified by making use of a special [convert]
project. There is surely a need for such a conversion library.
Oliver
>
> --
>
> Any of that kick off any thoughts?
>
> Hen
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [cli][configuration][convert] Architecting our overlaps
Posted by Andrew Shirley <ak...@decisionsoft.co.uk>.
On Sun, Sep 10, 2006 at 12:37:39AM -0700, Henri Yandell wrote:
> A third thought is that the CLI2 CommandLine API for the data itself
> rests on a getValue(Option);Object method, which implies some
> conversion is going on but I've not seen how yet by looking at the
> API.
This is done with an o.a.c.cli2.vlidation.Validator which is presented
with a List which it changes by replacing String objects with one of
their choice (FileValidator uses File objects for example).
> Configuration also does conversion of String to various objects.
> BeanUtils does that too, which gave rise to an overmodelled [convert]
> package that we've talked about restarting as something simpler.
The first step would be to split the Validation and Conversion and this
sounds like it is a problem which must have been encountered before.
There is the risk of making it even more verbose by having to specify
that you want the argument converted into a File and also that you want
to validate that the File exists. I'm sure we can work on a concise way
of doing this as it is a logical split and confusing as it stands.
Andrew Shirley
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org