public class OptionSpecBuilder
extends java.lang.Object
Instances are returned from OptionParser.accepts(String) to allow the formation of parser directives as
sentences in a "fluent interface" language. For example:
OptionParser parser = new OptionParser();
parser.accepts( "c" ).withRequiredArg().ofType( Integer.class );
If no methods are invoked on an instance of this class, then that instance's option will accept no argument.
Note that you should not use the fluent interface clauses in a way that would defeat the typing of option arguments:
OptionParser parser = new OptionParser();
ArgumentAcceptingOptionSpec<String> optionC =
parser.accepts( "c" ).withRequiredArg();
optionC.ofType( Integer.class ); // DON'T THROW AWAY THE TYPE!
String value = parser.parse( "-c", "2" ).valueOf( optionC ); // ClassCastException
| Modifier and Type | Method and Description |
|---|---|
boolean |
acceptsArguments()
Does this option accept arguments?
|
java.lang.String |
argumentDescription()
Gives a short description of the option's argument.
|
java.lang.String |
argumentTypeIndicator()
Gives an indication of the expected type of the option's
argument.
|
protected java.lang.Void |
convert(java.lang.String argument) |
java.util.List<java.lang.Void> |
defaultValues()
What values will the option take if none are specified on the command line?
|
java.lang.String |
description()
Description of this option's purpose.
|
boolean |
equals(java.lang.Object that) |
joptsimple.AbstractOptionSpec<V> |
forHelp() |
int |
hashCode() |
boolean |
isForHelp()
Tells whether this option is designated as a "help" option.
|
boolean |
isRequired()
Is this option required on a command line?
|
java.util.Collection<java.lang.String> |
options()
A set of options that are mutually synonymous.
|
boolean |
requiresArgument()
Does this option require an argument?
|
java.lang.String |
toString() |
V |
value(OptionSet detectedOptions)
Gives the argument associated with the given option in the given set of detected options.
|
java.util.List<V> |
values(OptionSet detectedOptions)
Gives any arguments associated with the given option in the given set of detected options.
|
ArgumentAcceptingOptionSpec<java.lang.String> |
withOptionalArg()
Informs an option parser that this builder's option accepts an optional argument.
|
ArgumentAcceptingOptionSpec<java.lang.String> |
withRequiredArg()
Informs an option parser that this builder's option requires an argument.
|
public ArgumentAcceptingOptionSpec<java.lang.String> withRequiredArg()
public ArgumentAcceptingOptionSpec<java.lang.String> withOptionalArg()
public boolean acceptsArguments()
OptionDescriptorpublic boolean requiresArgument()
OptionDescriptorpublic boolean isRequired()
OptionDescriptorpublic java.lang.String argumentDescription()
OptionDescriptorpublic java.lang.String argumentTypeIndicator()
OptionDescriptorprotected java.lang.Void convert(java.lang.String argument)
public java.util.List<java.lang.Void> defaultValues()
OptionDescriptorpublic final java.util.Collection<java.lang.String> options()
OptionDescriptoroptions in interface OptionDescriptoroptions in interface OptionSpec<V>public final java.util.List<V> values(OptionSet detectedOptions)
OptionSpecSpecifying a default argument value for this option will cause this method to return that default value even if this option was not detected on the command line, or if this option can take an optional argument but did not have one on the command line.
values in interface OptionSpec<V>detectedOptions - the detected options to search inOptionSet.valuesOf(OptionSpec)public final V value(OptionSet detectedOptions)
OptionSpecSpecifying a default argument value for this option will cause this method to return that default value even if this option was not detected on the command line, or if this option can take an optional argument but did not have one on the command line.
value in interface OptionSpec<V>detectedOptions - the detected options to search innull if no argument is present, or that option was not detectedOptionSet.valueOf(OptionSpec)public java.lang.String description()
OptionDescriptordescription in interface OptionDescriptorpublic final joptsimple.AbstractOptionSpec<V> forHelp()
public final boolean isForHelp()
OptionSpecisForHelp in interface OptionSpec<V>public boolean equals(java.lang.Object that)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object