V
- represents the type of the arguments this option acceptspublic interface OptionSpec<V>
Instances of this interface are returned by the "fluent interface" methods to allow retrieval of option arguments in a type-safe manner. Here's an example:
OptionParser parser = new OptionParser();
OptionSpec<Integer> count =
parser.accepts( "count" ).withRequiredArg().ofType( Integer.class );
OptionSet options = parser.parse( "--count", "2" );
assert options.has( count );
int countValue = options.valueOf( count );
assert countValue == count.value( options );
List<Integer> countValues = options.valuesOf( count );
assert countValues.equals( count.values( options ) );
Modifier and Type | Method and Description |
---|---|
boolean |
isForHelp()
Tells whether this option is designated as a "help" option.
|
List<String> |
options() |
V |
value(OptionSet detectedOptions)
Gives the argument associated with the given option in the given set of detected options.
|
default Optional<V> |
valueOptional(OptionSet detectedOptions)
Gives the argument associated with the given option in the given set of detected options
as an
Optional . |
List<V> |
values(OptionSet detectedOptions)
Gives any arguments associated with the given option in the given set of detected options.
|
List<V> values(OptionSet detectedOptions)
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.
detectedOptions
- the detected options to search inOptionException
- if there is a problem converting this option's arguments to the desired type; for
example, if the type does not implement a correct conversion constructor or methodNullPointerException
- if detectedOptions
is null
OptionSet.valuesOf(OptionSpec)
V value(OptionSet detectedOptions)
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.
detectedOptions
- the detected options to search innull
if no argument is present, or that option was not detectedOptionException
- if more than one argument was detected for the optionNullPointerException
- if detectedOptions
is null
ClassCastException
- if the arguments of this option are not of the expected typeOptionSet.valueOf(OptionSpec)
default Optional<V> valueOptional(OptionSet detectedOptions)
Optional
.
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.
detectedOptions
- the detected options to search inOptional
OptionException
- if more than one argument was detected for the optionNullPointerException
- if detectedOptions
is null
ClassCastException
- if the arguments of this option are not of the expected typeOptionSet.valueOf(OptionSpec)
boolean isForHelp()
© Copyright 2004-2016 Paul R. Holser, Jr. All rights reserved. Licensed under The MIT License.