Class OptionSpecBuilder
- java.lang.Object
-
- joptsimple.OptionSpecBuilder
-
- All Implemented Interfaces:
- OptionSpec<java.lang.Void>
public class OptionSpecBuilder extends java.lang.ObjectAllows 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
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanequals(java.lang.Object that)inthashCode()java.util.Collection<java.lang.String>options()java.lang.StringtoString()Vvalue(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.
-
-
-
Method Detail
-
withRequiredArg
public ArgumentAcceptingOptionSpec<java.lang.String> withRequiredArg()
Informs an option parser that this builder's option requires an argument.
- Returns:
- a specification for the option
-
withOptionalArg
public ArgumentAcceptingOptionSpec<java.lang.String> withOptionalArg()
Informs an option parser that this builder's option accepts an optional argument.
- Returns:
- a specification for the option
-
options
public final java.util.Collection<java.lang.String> options()
- Specified by:
optionsin interfaceOptionSpec<V>- Returns:
- the string representations of this option
-
values
public final java.util.List<V> values(OptionSet detectedOptions)
Description copied from interface: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.
- Specified by:
valuesin interfaceOptionSpec<V>- 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
- See Also:
OptionSet.valuesOf(OptionSpec)
-
value
public final V value(OptionSet detectedOptions)
Description copied from interface: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.
- Specified by:
valuein interfaceOptionSpec<V>- Parameters:
detectedOptions- the detected options to search in- Returns:
- the argument of the this option;
nullif no argument is present, or that option was not detected - See Also:
OptionSet.valueOf(OptionSpec)
-
equals
public boolean equals(java.lang.Object that)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG