commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Keyes <j...@mac.com>
Subject [CLI] OptionBuilder
Date Fri, 26 Jul 2002 23:55:52 GMT
I have 90% of OptionBuilder implemented.  The last piece to
provide is validation i.e. that all necessary information
has been provided.

In a previous thread it was recommended that an exception
be thrown if all of the required information is not present.
I think that only two properties are required:
   . opt (option character/string)
   . description (for usage documentation)

So I propose that the OptionBuilder does not have a
create() method, instead it provides the following
set of create methods:
   . create( char opt, String description )
   . create( String opt, String description )

The other public methods on OptionBuilder would then be:

   . hasArg()
   . hasMultipleArgs()
   . isRequired()
   . withType( Object type )
   . withLongOpt( String longopt )

A complete example using this approach would be:

Option simple
   = OptionBuilder.withLongOpt( "simple option")
                  .hasArg( )
                  .isRequired( )
                  .hasMultipleArgs( )
                  .withType( new Float( 10 ) )
                  .create( 's', "this is a simple option" );

A boolean option could be constructed as follows:

Option base
   = OptionBuilder.create( 's', "this is a simple option" );

The following will be the only public constructors for
Option:

   . Option( String opt, String description )
   . Option( char opt, String description )
   . Option( String opt, String description, boolean hasArg )
   . Option( char opt, String description, boolean hasArg )
   . Option( String opt, String description,
             boolean hasArg, String longOpt )
   . Option( char opt, String description,
             boolean hasArg, String longOpt )

The following will be the accessors:

   . setMultipleArgs
   . hasMultipleArgs
   . setRequired
   . getRequired
   . setType
   . getType
   . getOpt
   . getLongOpt
   . hasArg
   . getDescription

Phew!  So people let me know what you think of this and I'll
polish it up and commit.

Thanks,
-John K


--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message