Package fmpp.util
Class ArgsParser.OptionDefinition
- java.lang.Object
-
- fmpp.util.ArgsParser.OptionDefinition
-
- All Implemented Interfaces:
java.lang.Cloneable
- Enclosing class:
- ArgsParser
public class ArgsParser.OptionDefinition extends java.lang.Object implements java.lang.Cloneable
Describes and option. It does not store the actual value of the option after parsing; it is just the definition of the option.
-
-
Constructor Summary
Constructors Constructor Description OptionDefinition()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ArgsParser.OptionDefinition
copy(java.lang.String shortName, java.lang.String longName)
Creates a copy of the option with different short- and long-name, but with the same property name (and other attributes).ArgsParser.OptionDefinition
defaultArg(java.lang.String defaultValue)
Gives default argument value for an option that supports arguments, thus it will be optional to specify the argument value in the command-line.ArgsParser.OptionDefinition
desc(java.lang.String desc)
Sets the description (used in help) of the option.java.lang.String
getArgName()
Returns the name of the argument, or null if the option does not support argument.java.lang.String
getDefaultArg()
Returns the default argument of the option, or null if the option has no default argument.java.lang.String
getDescription()
Returns the description of the option, or null if no description is available.java.lang.String
getLongName()
Returns the long-name of the option, or null if the option has no long-name.java.lang.String
getShortName()
Returns the short-name of the option, or null if the option has no short-name.ArgsParser.OptionDefinition
group(java.lang.String propertyName)
Convenience method; same as callingproperty(propertyName, optionName)
, where optionName is the long-name if that exists, otherwise the short-name.void
hide()
Hides option, that is, it will not be shown in the option help.ArgsParser.OptionDefinition
implied()
Ensures that the option will be seemingly present if the args[] does not contains this option or any other option that mutually excludes this option.ArgsParser.OptionDefinition
implied(java.lang.String impliedArg)
Ensures that the option will be seemingly present with the given argument value if args[] does not contains this option, or any other option that mutually excludes this option.ArgsParser.OptionDefinition
property(java.lang.String pName)
Sets the property name for this option.ArgsParser.OptionDefinition
property(java.lang.String propertyName, java.lang.String propertyValue)
Convenience method; same as callingproperty(String)
and thenpropertyValue
.ArgsParser.OptionDefinition
propertyValue(java.lang.String value)
Sets the property value for this option.
-
-
-
Method Detail
-
property
public ArgsParser.OptionDefinition property(java.lang.String pName)
Sets the property name for this option. If you don't override the property name with this, it will be the long-name of the option if the option has long-name, otherwise the short-name of the option.- See Also:
property(String, String)
-
propertyValue
public ArgsParser.OptionDefinition propertyValue(java.lang.String value)
Sets the property value for this option. This only allowed for options that do no support argument, as the value of options that has argument will be the actual value of the argument. If you don't override the property value with this, it will be "" (0 length String) for those options.- Throws:
java.lang.IllegalArgumentException
- if the option has argument.- See Also:
property(String, String)
-
property
public ArgsParser.OptionDefinition property(java.lang.String propertyName, java.lang.String propertyValue)
Convenience method; same as callingproperty(String)
and thenpropertyValue
. This method only applies for options that do no support argument.- See Also:
property(String)
,propertyValue(java.lang.String)
-
group
public ArgsParser.OptionDefinition group(java.lang.String propertyName)
Convenience method; same as callingproperty(propertyName, optionName)
, where optionName is the long-name if that exists, otherwise the short-name. This method only applies for options that do no support argument.- See Also:
property(String)
,propertyValue(java.lang.String)
-
implied
public ArgsParser.OptionDefinition implied()
Ensures that the option will be seemingly present if the args[] does not contains this option or any other option that mutually excludes this option. Note that if the option supports argument, you have to useimplied(String)
.- Throws:
java.lang.IllegalArgumentException
- if the option has argument.- See Also:
implied(String)
-
implied
public ArgsParser.OptionDefinition implied(java.lang.String impliedArg)
Ensures that the option will be seemingly present with the given argument value if args[] does not contains this option, or any other option that mutually excludes this option. This version of the method applies only for options that support argument.- Throws:
java.lang.IllegalArgumentException
- if the option has no argument.- See Also:
implied()
-
defaultArg
public ArgsParser.OptionDefinition defaultArg(java.lang.String defaultValue)
Gives default argument value for an option that supports arguments, thus it will be optional to specify the argument value in the command-line.Note that introducing default value for an option is not a backward compatible step. For example if "color" has no default value, then "
--color red
" is interpreted as "color" has an argument that is "red". But, if "color" has a default value, then it is interpreted as "color" has the default value, and we have a non-option "red". Of coruse, there would not be problem if we use "--color=red
".
-
desc
public ArgsParser.OptionDefinition desc(java.lang.String desc)
Sets the description (used in help) of the option.
-
hide
public void hide()
Hides option, that is, it will not be shown in the option help.
-
copy
public ArgsParser.OptionDefinition copy(java.lang.String shortName, java.lang.String longName)
Creates a copy of the option with different short- and long-name, but with the same property name (and other attributes). This is mostly useful to create alias options.- Parameters:
longName
- the long-name of option or null. Do not use the long-name=ARGNAME form here.shortName
- the short-name of option or null. Do not use the s=ARGNAME form here.- Returns:
- the newly created
OptionDefinition
. - Throws:
java.lang.IllegalArgumentException
- If an option with the same long-name or short-name is already added, or if the given long- or short-name is malformed.
-
getArgName
public java.lang.String getArgName()
Returns the name of the argument, or null if the option does not support argument.
-
getDefaultArg
public java.lang.String getDefaultArg()
Returns the default argument of the option, or null if the option has no default argument.
-
getDescription
public java.lang.String getDescription()
Returns the description of the option, or null if no description is available.
-
getLongName
public java.lang.String getLongName()
Returns the long-name of the option, or null if the option has no long-name.
-
getShortName
public java.lang.String getShortName()
Returns the short-name of the option, or null if the option has no short-name.
-
-