Class ParsedOptions
- java.lang.Object
-
- com.aspectran.shell.command.option.ParsedOptions
-
- All Implemented Interfaces:
java.io.Serializable
public class ParsedOptions extends java.lang.Object implements java.io.Serializable
Represents list of arguments parsed against aOptions
descriptor.It allows querying of a boolean
hasOption(String opt)
, in addition to retrieving thegetValue(String opt)
for options requiring arguments.Additionally, any left-over or unrecognized arguments, are available for further processing.
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
ParsedOptions()
Creates a command line.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addArg(java.lang.String arg)
Add left-over unrecognized option/argument.protected void
addOption(Option opt)
Add an option.java.util.List<java.lang.String>
getArgList()
Retrieve any left-over non-recognized options and arguments.java.lang.String[]
getArgs()
Retrieve any left-over non-recognized options and arguments.Option[]
getOptions()
Returns an array of the processedOption
s.java.util.Properties
getProperties(Option option)
Retrieve the map of values associated to the option.java.util.Properties
getProperties(java.lang.String opt)
Retrieve the map of values associated to the option.<T> T
getTypedValue(char opt)
Return a version of thisOption
converted to a particular type.<T> T
getTypedValue(Option option)
Return a version of thisOption
converted to a particular type.<T> T
getTypedValue(java.lang.String opt)
Return a version of thisOption
converted to a particular type.java.lang.String
getValue(char opt)
Retrieve the first argument, if any, of this option.java.lang.String
getValue(char opt, java.lang.String defaultValue)
Retrieve the argument, if any, of an option.java.lang.String
getValue(Option option)
Retrieve the first argument, if any, of this option.java.lang.String
getValue(Option option, java.lang.String defaultValue)
Retrieve the first argument, if any, of an option.java.lang.String
getValue(java.lang.String opt)
Retrieve the first argument, if any, of this option.java.lang.String
getValue(java.lang.String opt, java.lang.String defaultValue)
Retrieve the first argument, if any, of an option.java.lang.String[]
getValues(char opt)
Retrieves the array of values, if any, of an option.java.lang.String[]
getValues(Option option)
Retrieves the array of values, if any, of an option.java.lang.String[]
getValues(java.lang.String opt)
Retrieves the array of values, if any, of an option.boolean
hasArgs()
Checks if non-recognized options or arguments exists.boolean
hasOption(char opt)
Query to see if an option has been set.boolean
hasOption(Option opt)
Query to see if an option has been set.boolean
hasOption(java.lang.String opt)
Query to see if an option has been set.boolean
hasOptions()
Checks if options exists.java.util.Iterator<Option>
iterator()
Returns an iterator over the Option members of ParsedOptions.
-
-
-
Method Detail
-
hasOption
public boolean hasOption(Option opt)
Query to see if an option has been set.- Parameters:
opt
- the option to check- Returns:
- true if set, false if not
-
hasOption
public boolean hasOption(java.lang.String opt)
Query to see if an option has been set.- Parameters:
opt
- short name of the option- Returns:
- true if set, false if not
-
hasOption
public boolean hasOption(char opt)
Query to see if an option has been set.- Parameters:
opt
- character name of the option- Returns:
- true if set, false if not
-
hasOptions
public boolean hasOptions()
Checks if options exists.- Returns:
- true if options exists; false otherwise
-
getTypedValue
public <T> T getTypedValue(Option option) throws OptionParserException
Return a version of thisOption
converted to a particular type.- Type Parameters:
T
- type to attempt to convert to- Parameters:
option
- the option- Returns:
- the value parsed into a particular object
- Throws:
OptionParserException
- if there are problems turning the option value into the desired type
-
getTypedValue
public <T> T getTypedValue(java.lang.String opt) throws OptionParserException
Return a version of thisOption
converted to a particular type.- Type Parameters:
T
- type to attempt to convert to- Parameters:
opt
- the name of the option- Returns:
- the value parsed into a particular object
- Throws:
OptionParserException
- if there are problems turning the option value into the desired type
-
getTypedValue
public <T> T getTypedValue(char opt) throws OptionParserException
Return a version of thisOption
converted to a particular type.- Type Parameters:
T
- type to attempt to convert to- Parameters:
opt
- the name of the option- Returns:
- the value parsed into a particular object
- Throws:
OptionParserException
- if there are problems turning the option value into the desired type
-
getValue
public java.lang.String getValue(Option option)
Retrieve the first argument, if any, of this option.- Parameters:
option
- the name of the option- Returns:
- the value of the argument if option is set, and has an argument,
otherwise
null
-
getValue
public java.lang.String getValue(java.lang.String opt)
Retrieve the first argument, if any, of this option.- Parameters:
opt
- the name of the option- Returns:
- the value of the argument if option is set, and has an argument,
otherwise
null
-
getValue
public java.lang.String getValue(char opt)
Retrieve the first argument, if any, of this option.- Parameters:
opt
- the character name of the option- Returns:
- the value of the argument if option is set, and has an argument,
otherwise
null
-
getValues
public java.lang.String[] getValues(Option option)
Retrieves the array of values, if any, of an option.- Parameters:
option
- string name of the option- Returns:
- the values of the argument if option is set, and has an argument,
otherwise
null
-
getValues
public java.lang.String[] getValues(java.lang.String opt)
Retrieves the array of values, if any, of an option.- Parameters:
opt
- string name of the option- Returns:
- the values of the argument if option is set, and has an argument,
otherwise
null
-
getValues
public java.lang.String[] getValues(char opt)
Retrieves the array of values, if any, of an option.- Parameters:
opt
- character name of the option- Returns:
- Values of the argument if option is set, and has an argument,
otherwise
null
-
getValue
public java.lang.String getValue(Option option, java.lang.String defaultValue)
Retrieve the first argument, if any, of an option.- Parameters:
option
- the name of the optiondefaultValue
- the default value to be returned if the option is not specified- Returns:
- the value of the argument if option is set, and has an argument,
otherwise
defaultValue
-
getValue
public java.lang.String getValue(java.lang.String opt, java.lang.String defaultValue)
Retrieve the first argument, if any, of an option.- Parameters:
opt
- the name of the optiondefaultValue
- the default value to be returned if the option is not specified- Returns:
- the value of the argument if option is set, and has an argument,
otherwise
defaultValue
-
getValue
public java.lang.String getValue(char opt, java.lang.String defaultValue)
Retrieve the argument, if any, of an option.- Parameters:
opt
- character name of the optiondefaultValue
- the default value to be returned if the option is not specified- Returns:
- the value of the argument if option is set, and has an argument,
otherwise
defaultValue
-
getProperties
public java.util.Properties getProperties(Option option)
Retrieve the map of values associated to the option. This is convenient for options specifying Java properties like-Dparam1=value1 -Dparam2=value2
. The first argument of the option is the key, and the 2nd argument is the value. If the option has only one argument (-Dfoo
) it is considered as a boolean flag and the value is"true"
.- Parameters:
option
- the option to be processed- Returns:
- the Properties mapped by the option, never
null
even if the option doesn't exists
-
getProperties
public java.util.Properties getProperties(java.lang.String opt)
Retrieve the map of values associated to the option. This is convenient for options specifying Java properties like-Dparam1=value1 -Dparam2=value2
. The first argument of the option is the key, and the 2nd argument is the value. If the option has only one argument (-Dfoo
) it is considered as a boolean flag and the value is"true"
.- Parameters:
opt
- the name of the option- Returns:
- the Properties mapped by the option, never
null
even if the option doesn't exists
-
addOption
protected void addOption(Option opt)
Add an option. The values of the option are stored.- Parameters:
opt
- the option to be processed
-
iterator
public java.util.Iterator<Option> iterator()
Returns an iterator over the Option members of ParsedOptions.- Returns:
- an
Iterator
over the processedOption
members of thisParsedOptions
-
getOptions
public Option[] getOptions()
Returns an array of the processedOption
s.- Returns:
- an array of the processed
Option
s
-
hasArgs
public boolean hasArgs()
Checks if non-recognized options or arguments exists.- Returns:
- true if non-recognized options or arguments exists; false otherwise
-
getArgs
public java.lang.String[] getArgs()
Retrieve any left-over non-recognized options and arguments.- Returns:
- remaining items passed in but not parsed as an array
-
getArgList
public java.util.List<java.lang.String> getArgList()
Retrieve any left-over non-recognized options and arguments.- Returns:
- remaining items passed in but not parsed as a
List
-
addArg
protected void addArg(java.lang.String arg)
Add left-over unrecognized option/argument.- Parameters:
arg
- the unrecognized option/argument
-
-