module Flags:sig
..end
Arg
, but if all you need is something very simple,
Flags
might do.exception Argument_missing of string
Flags.lookup.string
and Flags.lookup.int
when the requested argument isn't present.class type lookup =object
..end
Flags.go
returns an object for querying
its results.
val go : ?argv:string array -> ?usage:string -> string -> lookup
Flags.go spec
parses the command-line arguments according to
spec
and returns a lookup
object. If ?argv
is given, it uses
that rather than Sys.argv
; if ?usage
is given, it uses that as
the sample command in the usage message.
The spec
argument is a stylized sequence of arguments:
"-a"
and "--apple"
specify boolean flags."-a <N>"
and "--apple <Color>"
specify string arguments."-a <N:int>"
and "--apple <Color:int>"
specify integer arguments.
For example, we might use
"-q -v -b <Before:int> -a <After:int> --baz <Baz>"
to specify
a program that takes boolean flags "-q"
and "-v"
, integer
arguments "-b"
and "-a"
, and a string argument "--baz"
. If we
pass this string to Flags.go
and it returns an object
lookup
, we may then query lookup, for example:
lookup#bool "-q"
checks whether "-q"
was given.lookup#int "-b"
returns an integer if "-b"
was given, or raises
Flags.Argument_missing
otherwise.lookup#ints "-a"
returns a list of integers (possibly 0 length) for
each time "-a"
was given.lookup#string ~default:"-" "--baz"
returns the provided string if
"--baz"
was given, and "-"
otherwise.