Package org.apache.commons.cli
Class OptionBuilder
- java.lang.Object
-
- org.apache.commons.cli.OptionBuilder
-
public final class OptionBuilder extends java.lang.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
- Version:
- $Revision: 754830 $, $Date: 2009-03-16 00:26:44 -0700 (Mon, 16 Mar 2009) $
- Author:
- John Keyes (john at integralsource.com)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Optioncreate()Create an Option using the current settingsstatic Optioncreate(char opt)Create an Option using the current settings and with the specified Optionchar.static Optioncreate(java.lang.String opt)Create an Option using the current settings and with the specified Optionchar.static OptionBuilderhasArg()The next Option created will require an argument value.static OptionBuilderhasArg(boolean hasArg)The next Option created will require an argument value ifhasArgis true.static OptionBuilderhasArgs()The next Option created can have unlimited argument values.static OptionBuilderhasArgs(int num)The next Option created can havenumargument values.static OptionBuilderhasOptionalArg()The next Option can have an optional argument.static OptionBuilderhasOptionalArgs()The next Option can have an unlimited number of optional arguments.static OptionBuilderhasOptionalArgs(int numArgs)The next Option can have the specified number of optional arguments.static OptionBuilderisRequired()The next Option created will be required.static OptionBuilderisRequired(boolean newRequired)The next Option created will be required ifrequiredis true.static OptionBuilderwithArgName(java.lang.String name)The next Option created will have the specified argument value name.static OptionBuilderwithDescription(java.lang.String newDescription)The next Option created will have the specified descriptionstatic OptionBuilderwithLongOpt(java.lang.String newLongopt)The next Option created will have the following long option value.static OptionBuilderwithType(java.lang.Object newType)The next Option created will have a value that will be an instance oftype.static OptionBuilderwithValueSeparator()The next Option created uses '=' as a means to separate argument values.static OptionBuilderwithValueSeparator(char sep)The next Option created usessepas a means to separate argument values.
-
-
-
Method Detail
-
withLongOpt
public static OptionBuilder withLongOpt(java.lang.String newLongopt)
The next Option created will have the following long option value.- Parameters:
newLongopt- the long option value- Returns:
- the OptionBuilder instance
-
hasArg
public static OptionBuilder hasArg()
The next Option created will require an argument value.- Returns:
- the OptionBuilder instance
-
hasArg
public static OptionBuilder hasArg(boolean hasArg)
The next Option created will require an argument value ifhasArgis true.- Parameters:
hasArg- if true then the Option has an argument value- Returns:
- the OptionBuilder instance
-
withArgName
public static OptionBuilder withArgName(java.lang.String name)
The next Option created will have the specified argument value name.- Parameters:
name- the name for the argument value- Returns:
- the OptionBuilder instance
-
isRequired
public static OptionBuilder isRequired()
The next Option created will be required.- Returns:
- the OptionBuilder instance
-
withValueSeparator
public static OptionBuilder withValueSeparator(char sep)
The next Option created usessepas a means to separate argument values. Example:Option opt = OptionBuilder.withValueSeparator(':') .create('D'); CommandLine line = parser.parse(args); String propertyName = opt.getValue(0); String propertyValue = opt.getValue(1);- Parameters:
sep- The value separator to be used for the argument values.- Returns:
- the OptionBuilder instance
-
withValueSeparator
public static OptionBuilder withValueSeparator()
The next Option created uses '=' as a means to separate argument values. Example: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
-
isRequired
public static OptionBuilder isRequired(boolean newRequired)
The next Option created will be required ifrequiredis true.- Parameters:
newRequired- if true then the Option is required- Returns:
- the OptionBuilder instance
-
hasArgs
public static OptionBuilder hasArgs()
The next Option created can have unlimited argument values.- Returns:
- the OptionBuilder instance
-
hasArgs
public static OptionBuilder hasArgs(int num)
The next Option created can havenumargument values.- Parameters:
num- the number of args that the option can have- Returns:
- the OptionBuilder instance
-
hasOptionalArg
public static OptionBuilder hasOptionalArg()
The next Option can have an optional argument.- Returns:
- the OptionBuilder instance
-
hasOptionalArgs
public static OptionBuilder hasOptionalArgs()
The next Option can have an unlimited number of optional arguments.- Returns:
- the OptionBuilder instance
-
hasOptionalArgs
public static OptionBuilder hasOptionalArgs(int numArgs)
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
-
withType
public static OptionBuilder withType(java.lang.Object newType)
The next Option created will have a value that will be an instance oftype.- Parameters:
newType- the type of the Options argument value- Returns:
- the OptionBuilder instance
-
withDescription
public static OptionBuilder withDescription(java.lang.String newDescription)
The next Option created will have the specified description- Parameters:
newDescription- a description of the Option's purpose- Returns:
- the OptionBuilder instance
-
create
public static Option create(char opt) throws java.lang.IllegalArgumentException
Create an Option using the current settings and with the specified Optionchar.- Parameters:
opt- the character representation of the Option- Returns:
- the Option instance
- Throws:
java.lang.IllegalArgumentException- ifoptis not a valid character. See Option.
-
create
public static Option create() throws java.lang.IllegalArgumentException
Create an Option using the current settings- Returns:
- the Option instance
- Throws:
java.lang.IllegalArgumentException- iflongOpthas not been set.
-
create
public static Option create(java.lang.String opt) throws java.lang.IllegalArgumentException
Create an Option using the current settings and with the specified Optionchar.- Parameters:
opt- thejava.lang.Stringrepresentation of the Option- Returns:
- the Option instance
- Throws:
java.lang.IllegalArgumentException- ifoptis not a valid character. See Option.
-
-