A flag parameter has no specific value, it just signals that it is there.
A flag parameter has no specific value, it just signals that it is there.
If its value
is defined, it is present in the command line, else it is not.
Signals that the user needs some help.
Signals that the user needs some help.
If a help-parameter name is given as a command-line argument, other parameters are not computed and no parse exceptions are thrown.
If its value
is defined, it is present in the command line, else it is not.
A list parameter has a number of values specified by its arity
.
A list parameter has a number of values specified by its arity
.
The values can be retrieved as a sequence by the values
option.
A main parameter has a number of values specified by its arity
.
A main parameter has a number of values specified by its arity
.
The values can be retrieved as a sequence by the values
option.
A main parameter is different from a list parameter by the absence of a name
in the command line. There is, however, an internal name
(MainParameter.internalName
) that can be used in the command line to avoid
ambiguities.
Main-parameter values can be given at the beginning or at the end of the arguments sequence (or both mixed up, but that may be confusing). Beware, that values at the end might be consumed by a variable-arity parameter in a position right before.
A value parameter has exactly one value.
A value parameter has exactly one value.
The value can be retrieved by the value
option.
Define the parameters of your command line as instances of
-
FlagParameter
: no specific value, just signals that it is there,-
HelpParameter
: signals that the user needs some help (if given as a command-line argument, other parameters are not computed and no parse exceptions are thrown),-
ValueParameter[V]
: has exactly one value of typeV
,-
ListParameter[V]
: has a number of values of typeV
and-
MainParameter
: has a number ofString
values.ValueParameter[V]
andListParameter[V]
need a converter to convert a string to the value typeV
. You might want to import the objectConverter
that provides converters for standard data types implicitly by:import de.h2b.scala.lib.util.cli.Converter._
Then create a new instance of
CommandLine
with a set of parameters. The resulting object then can parse a string sequence or an array of strings for parameters and their values. If something goes wrong, either aParameterException
(some argument does not obey to the format specified by its parameter) or aCommandLineException
(something is wrong with the arguments as a whole) is thrown.Finally query the original parameter instances for its
value
orvalues
field.The
usage
method ofCommandLine
constructs a string suitable for a usage message.