Class Options
- java.lang.Object
-
- com.aspectran.shell.command.option.Options
-
- All Implemented Interfaces:
java.io.Serializable
public class Options extends java.lang.Object implements java.io.SerializableMain entry-point into the library.Options represents a collection of
Optionobjects, which describe the possible options for a command-line.It may flexibly parse long and short options, with or without values. Additionally, it may parse only a portion of a commandline, allowing for flexible multi-stage parsing.
- See Also:
ParsedOptions, Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Options()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionsaddOption(Option opt)Adds an option instance.OptionsaddOption(java.lang.String opt, boolean hasArg, java.lang.String description)Add an option that only contains a short-name.OptionsaddOption(java.lang.String opt, java.lang.String description)Add an option that only contains a short name.OptionsaddOption(java.lang.String opt, java.lang.String longOpt, boolean hasArg, java.lang.String description)Add an option that contains a short-name and a long-name.OptionsaddOptionGroup(OptionGroup group)Add the specified option group.OptionsaddRequiredOption(java.lang.String opt, java.lang.String longOpt, boolean hasArg, java.lang.String description)Add an option that contains a short-name and a long-name.java.util.List<java.lang.String>getMatchingOptions(java.lang.String opt)Returns the options with a long name starting with the name specified.OptiongetOption(java.lang.String opt)Retrieve theOptionmatching the long or short name specified.OptionGroupgetOptionGroup(Option opt)Returns the OptionGroup theoptbelongs to.java.util.Collection<Option>getOptions()Retrieve a read-only list of options in this set.java.util.List<java.lang.Object>getRequiredOptions()Returns the required options.booleanhasLongOption(java.lang.String opt)booleanhasOption(java.lang.String opt)booleanhasShortOption(java.lang.String opt)booleanisEmpty()Returnstrueif no options have been added.java.lang.StringtoString()Dump state, suitable for debugging.
-
-
-
Method Detail
-
addOptionGroup
public Options addOptionGroup(OptionGroup group)
Add the specified option group.- Parameters:
group- the OptionGroup that is to be added- Returns:
- the resulting Options instance
-
addOption
public Options addOption(java.lang.String opt, java.lang.String description)
Add an option that only contains a short name.The option does not take an argument.
- Parameters:
opt- Short single-character name of the option.description- Self-documenting description- Returns:
- the resulting Options instance
-
addOption
public Options addOption(java.lang.String opt, boolean hasArg, java.lang.String description)
Add an option that only contains a short-name.It may be specified as requiring an argument.
- Parameters:
opt- Short single-character name of the option.hasArg- flag signalling if an argument is required after this optiondescription- Self-documenting description- Returns:
- the resulting Options instance
-
addOption
public Options addOption(java.lang.String opt, java.lang.String longOpt, boolean hasArg, java.lang.String description)
Add an option that contains a short-name and a long-name.It may be specified as requiring an argument.
- Parameters:
opt- Short single-character name of the option.longOpt- Long multi-character name of the option.hasArg- flag signalling if an argument is required after this optiondescription- Self-documenting description- Returns:
- the resulting Options instance
-
addRequiredOption
public Options addRequiredOption(java.lang.String opt, java.lang.String longOpt, boolean hasArg, java.lang.String description)
Add an option that contains a short-name and a long-name.The added option is set as required. It may be specified as requiring an argument. This method is a shortcut for:
Options option = new Option(opt, longOpt, hasArg, description); option.setRequired(true); options.add(option);- Parameters:
opt- short single-character name of the optionlongOpt- long multi-character name of the optionhasArg- flag signalling if an argument is required after this optiondescription- Self-documenting description- Returns:
- the resulting Options instance
-
addOption
public Options addOption(Option opt)
Adds an option instance.- Parameters:
opt- the option that is to be added- Returns:
- the resulting Options instance
-
isEmpty
public boolean isEmpty()
Returnstrueif no options have been added.- Returns:
trueif no options have been added
-
getOptions
public java.util.Collection<Option> getOptions()
Retrieve a read-only list of options in this set.- Returns:
- read-only Collection of
Optionobjects in this descriptor
-
getRequiredOptions
public java.util.List<java.lang.Object> getRequiredOptions()
Returns the required options.- Returns:
- read-only List of required options
-
getOption
public Option getOption(java.lang.String opt)
Retrieve theOptionmatching the long or short name specified.The leading hyphens in the name are ignored (up to 2).
- Parameters:
opt- short or long name of theOption- Returns:
- the option represented by opt
-
getMatchingOptions
public java.util.List<java.lang.String> getMatchingOptions(java.lang.String opt)
Returns the options with a long name starting with the name specified.- Parameters:
opt- the partial name of the option- Returns:
- the options matching the partial name specified, or an empty list if none matches
-
hasOption
public boolean hasOption(java.lang.String opt)
-
hasLongOption
public boolean hasLongOption(java.lang.String opt)
-
hasShortOption
public boolean hasShortOption(java.lang.String opt)
-
getOptionGroup
public OptionGroup getOptionGroup(Option opt)
Returns the OptionGroup theoptbelongs to.- Parameters:
opt- the option whose OptionGroup is being queried.- Returns:
- the OptionGroup if
optis part of an OptionGroup, otherwise return null
-
toString
public java.lang.String toString()
Dump state, suitable for debugging.- Overrides:
toStringin classjava.lang.Object- Returns:
- the stringified form of this object
-
-