|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjoptsimple.OptionSpecBuilder
public class OptionSpecBuilder
Allows callers to specify whether a given option accepts arguments (required or optional).
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
| Method Summary | |
|---|---|
protected Void |
convert(String argument)
|
boolean |
equals(Object that)
|
int |
hashCode()
|
Collection<String> |
options()
|
String |
toString()
|
V |
value(OptionSet detectedOptions)
Gives the argument associated with the given option in the given set of detected options. |
List<V> |
values(OptionSet detectedOptions)
Gives any arguments associated with the given option in the given set of detected options. |
ArgumentAcceptingOptionSpec<String> |
withOptionalArg()
Informs an option parser that this builder's option accepts an optional argument. |
ArgumentAcceptingOptionSpec<String> |
withRequiredArg()
Informs an option parser that this builder's option requires an argument. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public ArgumentAcceptingOptionSpec<String> withRequiredArg()
Informs an option parser that this builder's option requires an argument.
public ArgumentAcceptingOptionSpec<String> withOptionalArg()
Informs an option parser that this builder's option accepts an optional argument.
protected Void convert(String argument)
public final Collection<String> options()
options in interface OptionSpec<V>public final List<V> values(OptionSet detectedOptions)
OptionSpecGives any arguments associated with the given option in the given set of detected options.
Specifying 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 in
OptionSet.valuesOf(OptionSpec)public final V value(OptionSet detectedOptions)
OptionSpecGives the argument associated with the given option in the given set of detected options.
Specifying 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 in
null if no argument is present,
or that option was not detectedOptionSet.valueOf(OptionSpec)public boolean equals(Object that)
equals in class Objectpublic int hashCode()
hashCode in class Objectpublic String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||