Class NonOptionArgumentSpec<V>
- java.lang.Object
-
- joptsimple.AbstractOptionSpec<V>
-
- joptsimple.NonOptionArgumentSpec<V>
-
- Type Parameters:
V
- represents the type of the non-option arguments
- All Implemented Interfaces:
OptionDescriptor
,OptionSpec<V>
public class NonOptionArgumentSpec<V> extends AbstractOptionSpec<V>
Specification of a command line's non-option arguments.
Instances are returned from
OptionParser
methods to allow the formation of parser directives as sentences in a "fluent interface" language. For example:OptionParser parser = new OptionParser(); parser.nonOptions( "files to be processed" ).ofType( File.class );
If no methods are invoked on an instance of this class, then that instance's option will treat the non-option arguments as
String
s.
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
argumentDescription
private ValueConverter<V>
converter
(package private) static java.lang.String
NAME
-
Constructor Summary
Constructors Constructor Description NonOptionArgumentSpec()
NonOptionArgumentSpec(java.lang.String description)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 V
convert(java.lang.String argument)
java.util.List<?>
defaultValues()
What values will the option take if none are specified on the command line?NonOptionArgumentSpec<V>
describedAs(java.lang.String description)
Specifies a description for the non-option arguments that this spec represents.(package private) void
handleOption(OptionParser parser, ArgumentList arguments, OptionSet detectedOptions, java.lang.String detectedArgument)
boolean
isRequired()
Is this option required on a command line?<T> NonOptionArgumentSpec<T>
ofType(java.lang.Class<T> argumentType)
Specifies a type to which the non-option arguments are to be converted.boolean
representsNonOptions()
Tells whether this object represents the non-option arguments of a command line.boolean
requiresArgument()
Does this option require an argument?<T> NonOptionArgumentSpec<T>
withValuesConvertedBy(ValueConverter<T> aConverter)
Specifies a converter to use to translate non-option arguments into Java objects.-
Methods inherited from class joptsimple.AbstractOptionSpec
argumentTypeIndicatorFrom, convertWith, description, equals, forHelp, hashCode, isForHelp, options, toString, value, values
-
-
-
-
Field Detail
-
NAME
static final java.lang.String NAME
- See Also:
- Constant Field Values
-
converter
private ValueConverter<V> converter
-
argumentDescription
private java.lang.String argumentDescription
-
-
Method Detail
-
ofType
public <T> NonOptionArgumentSpec<T> ofType(java.lang.Class<T> argumentType)
Specifies a type to which the non-option arguments are to be converted.
JOpt Simple accepts types that have either:
- a public static method called
valueOf
which accepts a single argument of typeString
and whose return type is the same as the class on which the method is declared. Thejava.lang
primitive wrapper classes have such methods. - a public constructor which accepts a single argument of type
String
.
This class converts arguments using those methods in that order; that is,
valueOf
would be invoked before a one-String
-arg constructor would.Invoking this method will trump any previous calls to this method or to
withValuesConvertedBy(ValueConverter)
.- Type Parameters:
T
- represents the runtime class of the desired option argument type- Parameters:
argumentType
- desired type of arguments to this spec's option- Returns:
- self, so that the caller can add clauses to the fluent interface sentence
- Throws:
java.lang.NullPointerException
- if the type isnull
java.lang.IllegalArgumentException
- if the type does not have the standard conversion methods
- a public static method called
-
withValuesConvertedBy
public final <T> NonOptionArgumentSpec<T> withValuesConvertedBy(ValueConverter<T> aConverter)
Specifies a converter to use to translate non-option arguments into Java objects. This is useful when converting to types that do not have the requisite factory method or constructor for
ofType(Class)
.Invoking this method will trump any previous calls to this method or to
ofType(Class)
.- Type Parameters:
T
- represents the runtime class of the desired non-option argument type- Parameters:
aConverter
- the converter to use- Returns:
- self, so that the caller can add clauses to the fluent interface sentence
- Throws:
java.lang.NullPointerException
- if the converter isnull
-
describedAs
public NonOptionArgumentSpec<V> describedAs(java.lang.String description)
Specifies a description for the non-option arguments that this spec represents. This description is used when generating help information about the parser.
- Parameters:
description
- describes the nature of the argument of this spec's option- Returns:
- self, so that the caller can add clauses to the fluent interface sentence
-
convert
protected final V convert(java.lang.String argument)
- Specified by:
convert
in classAbstractOptionSpec<V>
-
handleOption
void handleOption(OptionParser parser, ArgumentList arguments, OptionSet detectedOptions, java.lang.String detectedArgument)
- Specified by:
handleOption
in classAbstractOptionSpec<V>
-
defaultValues
public java.util.List<?> defaultValues()
Description copied from interface:OptionDescriptor
What values will the option take if none are specified on the command line?- Returns:
- any default values for the option
-
isRequired
public boolean isRequired()
Description copied from interface:OptionDescriptor
Is this option required on a command line?- Returns:
- whether the option is required
-
acceptsArguments
public boolean acceptsArguments()
Description copied from interface:OptionDescriptor
Does this option accept arguments?- Returns:
- whether the option accepts arguments
-
requiresArgument
public boolean requiresArgument()
Description copied from interface:OptionDescriptor
Does this option require an argument?- Returns:
- whether the option requires an argument
-
argumentDescription
public java.lang.String argumentDescription()
Description copied from interface:OptionDescriptor
Gives a short description of the option's argument.- Returns:
- a description for the option's argument
-
argumentTypeIndicator
public java.lang.String argumentTypeIndicator()
Description copied from interface:OptionDescriptor
Gives an indication of the expected type of the option's argument.- Returns:
- a description for the option's argument type
-
representsNonOptions
public boolean representsNonOptions()
Description copied from interface:OptionDescriptor
Tells whether this object represents the non-option arguments of a command line.- Specified by:
representsNonOptions
in interfaceOptionDescriptor
- Overrides:
representsNonOptions
in classAbstractOptionSpec<V>
- Returns:
true
if this represents non-option arguments
-
-