@Retention(value=RUNTIME) @Target(value=FIELD) public static @interface CommandLine.Parameters
Fields annotated with @Parameters
will be initialized with positional parameters. By specifying the
index()
attribute you can pick which (or what range) of the positional parameters to apply. If no index
is specified, the field will get all positional parameters (so it should be an array or a collection).
When parsing the command line arguments, picocli first tries to match arguments to Options
.
Positional parameters are the arguments that follow the options, or the arguments that follow a "--" (double
dash) argument on the command line.
For example:
import static picocli.CommandLine.*; public class MyCalcParameters { @Parameters(type = BigDecimal.class, description = "Any number of input numbers") private List<BigDecimal> files = new ArrayList<BigDecimal>(); @Option(names = { "-h", "--help", "-?", "-help"}, help = true, description = "Display this help and exit") private boolean help; }
A field cannot be annotated with both @Parameters
and @Option
or a ParameterException
is thrown.
Modifier and Type | Optional Element and Description |
---|---|
String |
arity
Specifies the minimum number of required parameters and the maximum number of accepted parameters.
|
String[] |
description
Description of the parameter(s), used when generating the usage documentation.
|
boolean |
hidden
Set
hidden=true if this parameter should not be included in the usage message. |
String |
index
Specify an index ("0", or "1", etc.) to pick which of the command line arguments should be assigned to this
field.
|
String |
paramLabel
Specify a
paramLabel for the parameter to be used in the usage help message. |
String |
split
Specify a regular expression to use to split positional parameter values before applying them to the field.
|
Class<?> |
type
Specify a
type if the annotated field is a Collection that should hold objects other than Strings. |
public abstract String index
public abstract String[] description
public abstract String arity
CommandLine.MissingParameterException
is thrown by the CommandLine.parse(String...)
method.
The default depends on the type of the parameter: booleans require no parameters, arrays and Collections accept zero to any number of parameters, and any other type accepts one parameter.
public abstract String paramLabel
paramLabel
for the parameter to be used in the usage help message. If omitted,
picocli uses the field name in fish brackets ('<'
and '>'
) by default. Example:
class Example { @Parameters(paramLabel="FILE", description="path of the input FILE(s)") private File[] inputFiles; }
By default, the above gives a usage help message like the following:
Usage: <main class> [FILE...] [FILE...] path of the input FILE(s)
public abstract Class<?> type
Specify a type
if the annotated field is a Collection
that should hold objects other than Strings.
If the field's type is a Collection
, the generic type parameter of the collection is erased and
cannot be determined at runtime. Specify a type
attribute to store values other than String in
the Collection. Picocli will use the CommandLine.ITypeConverter
that is registered for that type to convert
the raw String values before they are added to the collection.
When the field's type is an array, the type
attribute is ignored: the values will be converted
to the array component type and the array will be replaced with a new instance containing both the old and
the new values.
public abstract String split
""
if the value should not be splitString.split(String)
Copyright © 1999-2018 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.