Package com.Ostermiller.util
Class CmdLnOption
java.lang.Object
com.Ostermiller.util.CmdLnOption
A command line option used by the CommandLineOptions parser.
More information about this class and code samples for suggested use are
available from ostermiller.org.
- Since:
- ostermillerutils 1.07.00
- Author:
- Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
-
Constructor Summary
ConstructorsConstructorDescriptionCmdLnOption(char[] shortNames) CmdLnOption(Character shortName) CmdLnOption(String longName) CmdLnOption(String[] longNames) CmdLnOption(String[] longNames, char[] shortNames) CmdLnOption(String longName, Character shortName) -
Method Summary
Modifier and TypeMethodDescriptionaddLongName(String name) addLongNames(String[] longNames) addLongNames(Collection<String> longNames) addShortName(Character name) addShortNames(char[] shortNames) addShortNames(Character[] shortNames) addShortNames(Collection<Character> shortNames) An object that may be set by the user.setArgumentBounds(int minArguments, int maxArguments) Sets the bounds for command line arguments.setDescription(String description) setListener(CmdLnListener callback) Set the call back objectSets the argument bounds to require no arguments (zero arguments minimum, zero arguments maximum).Sets the argument bounds for a single optional argument (zero arguments minimum, one argument maximum).Sets the argument bounds for a single required argument (one argument minimum, one argument maximum).Sets the argument bounds for unlimited (but optional) arguments (zero arguments minimum, Integer.MAX_VALUE arguments maximum).setUserObject(Object userObject) An object that may be set by the user.toString()Get a short string description this option.
-
Constructor Details
-
CmdLnOption
- Parameters:
longNames- list long names for this option- Throws:
IllegalArgumentException- if the the list does not contain at least one long name- Since:
- ostermillerutils 1.07.00
-
CmdLnOption
public CmdLnOption(char[] shortNames) - Parameters:
shortNames- list short names for this option- Throws:
IllegalArgumentException- if the the list does not contain at least one short name- Since:
- ostermillerutils 1.07.00
-
CmdLnOption
- Parameters:
longName- the long name for this option- Throws:
IllegalArgumentException- if the name is null- Since:
- ostermillerutils 1.07.00
-
CmdLnOption
- Parameters:
shortName- the short name for this option- Since:
- ostermillerutils 1.07.00
-
CmdLnOption
- Parameters:
longNames- list long names for this optionshortNames- list short names for this option- Throws:
IllegalArgumentException- if the the lists do not contain at least one name- Since:
- ostermillerutils 1.07.00
-
CmdLnOption
- Parameters:
longName- the long name for this optionshortName- the short name for this option- Since:
- ostermillerutils 1.07.00
-
-
Method Details
-
setNoArguments
Sets the argument bounds to require no arguments (zero arguments minimum, zero arguments maximum). This is the default state for a new command line option.- Returns:
- this command line option for method chaining
- Throws:
IllegalStateException- if this argument has already been used in parsing CommandLineOptions- Since:
- ostermillerutils 1.07.00
-
setOptionalArgument
Sets the argument bounds for a single optional argument (zero arguments minimum, one argument maximum).- Returns:
- this command line option for method chaining
- Throws:
IllegalStateException- if this argument has already been used in parsing CommandLineOptions- Since:
- ostermillerutils 1.07.00
-
setRequiredArgument
Sets the argument bounds for a single required argument (one argument minimum, one argument maximum).- Returns:
- this command line option for method chaining
- Throws:
IllegalStateException- if this argument has already been used in parsing CommandLineOptions- Since:
- ostermillerutils 1.07.00
-
setUnlimitedArguments
Sets the argument bounds for unlimited (but optional) arguments (zero arguments minimum, Integer.MAX_VALUE arguments maximum).- Returns:
- this command line option for method chaining
- Throws:
IllegalStateException- if this argument has already been used in parsing CommandLineOptions
-
setArgumentBounds
Sets the bounds for command line arguments.- Parameters:
minArguments- the minimum number of arguments this command line option should expectmaxArguments- the maximum number of arguments this command line option will accept- Returns:
- this command line option for method chaining
- Throws:
IllegalArgumentException- if minimum arguments is negativeIllegalArgumentException- if maximum arguments is less than minimum argumentsIllegalStateException- if this argument has already been used in parsing CommandLineOptions- Since:
- ostermillerutils 1.07.00
-
addLongNames
- Parameters:
longNames- long names to be added- Returns:
- this for method chaining
- Throws:
IllegalArgumentException- if the name is null or blank- Since:
- ostermillerutils 1.07.00
-
addLongNames
- Parameters:
longNames- long names to be added- Returns:
- this for method chaining
- Throws:
IllegalArgumentException- if the name is null or blank- Since:
- ostermillerutils 1.07.00
-
addLongName
- Parameters:
name- long name to be added- Returns:
- this for method chaining
- Throws:
IllegalArgumentException- if the name is null or blank- Since:
- ostermillerutils 1.07.00
-
addShortNames
- Parameters:
shortNames- short names to be added- Returns:
- this for method chaining
- Throws:
IllegalArgumentException- if the name is null or blank- Since:
- ostermillerutils 1.07.00
-
addShortNames
- Parameters:
shortNames- short names to be added- Returns:
- this for method chaining
- Throws:
IllegalArgumentException- if the name is null or blank- Since:
- ostermillerutils 1.07.00
-
addShortNames
- Parameters:
shortNames- short names to be added- Returns:
- this for method chaining
- Throws:
IllegalArgumentException- if the name is null or blank- Since:
- ostermillerutils 1.07.00
-
addShortName
- Parameters:
name- short name to be added- Returns:
- this for method chaining
- Throws:
IllegalArgumentException- if the name is null or blank- Since:
- ostermillerutils 1.07.00
-
toString
Get a short string description this option. It will be either the long name (if it has one) or the short name if it does not have a long name -
setListener
Set the call back object- Parameters:
callback- the call back object- Returns:
- this for method chaining
- Since:
- ostermillerutils 1.07.00
-
getUserObject
An object that may be set by the user. Suggested use: set the user object to an enum value that can be used in a switch statement.- Returns:
- the userObject
- Since:
- ostermillerutils 1.07.00
-
setUserObject
An object that may be set by the user. Suggested use: set the user object to an enum value that can be used in a switch statement.- Parameters:
userObject- the userObject to set- Returns:
- this for method chaining
- Since:
- ostermillerutils 1.07.00
-
getDescription
- Returns:
- the description used in the help message or null if no description has been set.
- Since:
- ostermillerutils 1.07.00
-
setDescription
- Parameters:
description- the description used in the help message- Returns:
- this for method chaining
- Since:
- ostermillerutils 1.07.00
-