joptsimple
Interface OptionSpec<V>

Type Parameters:
V - represents the type of the arguments this option accepts
All Known Implementing Classes:
ArgumentAcceptingOptionSpec, OptionSpecBuilder

public interface OptionSpec<V>

Describes options that an option parser recognizes.

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 ) );
 


Method Summary
 java.util.Collection<java.lang.String> options()
           
 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.
 

Method Detail

values

java.util.List<V> values(OptionSet detectedOptions)

Gives any arguments associated with the given option in the given set of detected options.

Parameters:
detectedOptions - the detected options to search in
Returns:
the arguments associated with this option; an empty list if no such arguments are present, or if this option was not detected
Throws:
OptionException - 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 method
java.lang.NullPointerException - if detectedOptions is null

value

V value(OptionSet detectedOptions)

Gives the argument associated with the given option in the given set of detected options.

Parameters:
detectedOptions - the detected options to search in
Returns:
the argument of the this option; null if no argument is present, or that option was not detected
Throws:
OptionException - if more than one argument was detected for the option
java.lang.NullPointerException - if detectedOptions is null
java.lang.ClassCastException - if the arguments of this option are not of the expected type

options

java.util.Collection<java.lang.String> options()
Returns:
the string representations of this option