org.apache.commons.cli
public class OptionBuilder extends Object
OptionBuilder allows the user to create Options using descriptive methods.
Details on the Builder pattern can be found at http://c2.com/cgi-bin/wiki?BuilderPattern.
Since: 1.0
| Field Summary | |
|---|---|
| static String | argName argument name |
| static String | description option description |
| static OptionBuilder | instance option builder instance |
| static String | longopt long option |
| static int | numberOfArgs the number of arguments |
| static boolean | optionalArg option can have an optional argument value |
| static boolean | required is required? |
| static Object | type option type |
| static char | valuesep value separator for argument value |
| Constructor Summary | |
|---|---|
| OptionBuilder() | |
| Method Summary | |
|---|---|
| static Option | create(char opt) Create an Option using the current settings and with
the specified Option |
| static Option | create() Create an Option using the current settings |
| static Option | create(String opt) Create an Option using the current settings and with
the specified Option |
| static OptionBuilder | hasArg() The next Option created will require an argument value. |
| static OptionBuilder | hasArg(boolean hasArg) The next Option created will require an argument value if
|
| static OptionBuilder | hasArgs() The next Option created can have unlimited argument values. |
| static OptionBuilder | hasArgs(int num) The next Option created can have |
| static OptionBuilder | hasOptionalArg() The next Option can have an optional argument. |
| static OptionBuilder | hasOptionalArgs() The next Option can have an unlimited number of optional arguments. |
| static OptionBuilder | hasOptionalArgs(int numArgs) The next Option can have the specified number of optional arguments. |
| static OptionBuilder | isRequired() The next Option created will be required. |
| static OptionBuilder | isRequired(boolean required) The next Option created will be required if |
| static void | reset() Resets the member variables to their default values. |
| static OptionBuilder | withArgName(String name) The next Option created will have the specified argument value name. |
| static OptionBuilder | withDescription(String description) The next Option created will have the specified description |
| static OptionBuilder | withLongOpt(String longopt) The next Option created will have the following long option value. |
| static OptionBuilder | withType(Object type) The next Option created will have a value that will be an instance
of |
| static OptionBuilder | withValueSeparator(char sep) The next Option created uses
Option opt = OptionBuilder.withValueSeparator( ':' )
.create( 'D' );
CommandLine line = parser.parse( args );
String propertyName = opt.getValue( 0 );
String propertyValue = opt.getValue( 1 );
|
| static OptionBuilder | withValueSeparator() The next Option created uses '
Option opt = OptionBuilder.withValueSeparator( )
.create( 'D' );
CommandLine line = parser.parse( args );
String propertyName = opt.getValue( 0 );
String propertyValue = opt.getValue( 1 );
|
Create an Option using the current settings and with
the specified Option char.
Parameters: opt the character representation of the Option
Returns: the Option instance
Throws: IllegalArgumentException if opt is not
a valid character. See Option.
Create an Option using the current settings
Returns: the Option instance
Throws: IllegalArgumentException if longOpt has
not been set.
Create an Option using the current settings and with
the specified Option char.
Parameters: opt the java.lang.String representation
of the Option
Returns: the Option instance
Throws: IllegalArgumentException if opt is not
a valid character. See Option.
The next Option created will require an argument value.
Returns: the OptionBuilder instance
The next Option created will require an argument value if
hasArg is true.
Parameters: hasArg if true then the Option has an argument value
Returns: the OptionBuilder instance
The next Option created can have unlimited argument values.
Returns: the OptionBuilder instance
The next Option created can have num
argument values.
Parameters: num the number of args that the option can have
Returns: the OptionBuilder instance
The next Option can have an optional argument.
Returns: the OptionBuilder instance
The next Option can have an unlimited number of optional arguments.
Returns: the OptionBuilder instance
The next Option can have the specified number of optional arguments.
Parameters: numArgs - the maximum number of optional arguments the next Option created can have.
Returns: the OptionBuilder instance
The next Option created will be required.
Returns: the OptionBuilder instance
The next Option created will be required if required
is true.
Parameters: required if true then the Option is required
Returns: the OptionBuilder instance
Resets the member variables to their default values.
The next Option created will have the specified argument value name.
Parameters: name the name for the argument value
Returns: the OptionBuilder instance
The next Option created will have the specified description
Parameters: description a description of the Option's purpose
Returns: the OptionBuilder instance
The next Option created will have the following long option value.
Parameters: longopt the long option value
Returns: the OptionBuilder instance
The next Option created will have a value that will be an instance
of type.
Parameters: type the type of the Options argument value
Returns: the OptionBuilder instance
The next Option created uses sep as a means to
separate argument values.
Option opt = OptionBuilder.withValueSeparator( ':' )
.create( 'D' );
CommandLine line = parser.parse( args );
String propertyName = opt.getValue( 0 );
String propertyValue = opt.getValue( 1 );
Returns: the OptionBuilder instance
The next Option created uses '=' as a means to
separate argument values.
Option opt = OptionBuilder.withValueSeparator( )
.create( 'D' );
CommandLine line = parser.parse( args );
String propertyName = opt.getValue( 0 );
String propertyValue = opt.getValue( 1 );
Returns: the OptionBuilder instance