Contains the options defined, the current values, which are the defaults before parsing and afterwards are the defaults overridden by the actual invocation options, and contains any parsing errors that were found, which is empty before parse is called.
Contains the options defined, the current values, which are the defaults
before parsing and afterwards are the defaults overridden by the actual
invocation options, and contains any parsing errors that were found, which
is empty before parse is called. In order to properly construct the default
values, this constructor is protected. Instead, use the companion Args.apply
to construct initial instances correctly. Subsequent calls to Args.parse
return
new, updated instances.
A command-line option, which might actually be required, with a corresponding value.
A command-line option, which might actually be required, with a corresponding value. It has the following fields:
name
- serve as a lookup key for retrieving the value.flags
- the arguments that invoke the option, e.g., -h
and --help
.help
- a message displayed for command-line help.default
- an optional default value, for when the user doesn't specify the option.required
- the user must specify this option on the command line.
This flag is effectively ignored if a default
is provided.parser
- An implementation feature for parsing arguments.fromString: String => V
- convert the found value from a String to the correct type.Specify the command-line arguments using a single, multi-line string.
Specify the command-line arguments using a single, multi-line string. Note the following example:
import com.concurrentthought.cla._ val args: Args = """ |java -cp ... foo |Some description |and a second line. | [-i | --in | --input string] Path to input file. | [-o | --out | --output string=/dev/null] Path to output file. | [-l | --log | --log-level int=3] Log level to use. | -p | --path path Path elements separated by ':' (*nix) or ';' (Windows). | [-q | --quiet flag] Suppress some verbose output. | [--things seq([-|])] String elements separated by '-' or '|'. | others Other stuff. |Any additional help description lines, |which also have no leading whitespace. |""".stripMargin.toArgs
The format, as illustrated in the example, has the following requirements:
Args.remaining
).
Note that these tokens are handled whether or not you specify a line like
this or not.Opt
: string
, byte
, char
, int
, long
, float
, double
, path
,
seqString
, where the string "seq" is used, followed by a required
(delim)
suffix to specify the delimiter regex as shown in the example, and
flag
which indicates a boolean flag where no value is expected, but the
flag's presence means true
and absence means false
.
However, for a no-flag option, the value in this column is interpreted as a
name for the option for the help message. This is the one case where the string
isn't interpreted as a type specifier.
The =
indicates the default value to use, if present. Current limitations
of the type specification include the following: (i) Opt.seq[V]
isn't
supported in this mechanism, (ii) default values can't be specified for
the path
or seq
types, nor for the no-flag case (an implementation limitation).This is an experimental feature. There are several known limitations:
Args.quietFlag
,
although Args.helpFlag
and Args.remainingOpt
are automatically added
if the list of options doesn't explicitly define help and no-flag constructs.Opt.seq[V]
isn't supported, only Opt.seqString
.Demonstrates how to use the API.
Demonstrates how to use the API. Try running with different arguments,
including --help
. Try running the following examples within SBT:
run-main com.concurrentthought.cla.CLASampleMain -h run -h run --help run -i /in -o /out -l 4 -p a:b --things x-y|z foo bar baz run --in /in --out=/out -l=4 --path "a:b" --things=x-y|z -q foo bar baz
The last example demonstrates that both argflag value
and argflag=value
syntax is supported. The "[...]" indicate optional arguments, so in this example,
you must specify the input
argument and at least one token for "others".
A set of "Elements", used for convenient access from clients.
Format a help message for the command-line invocation of a program, based
on the Args
object passed to apply
.
Parse a line defining an option.
Package object that adds a mini-DSL allowing the user to construct an
Args
using using a multi-line string.Experimental!