Pa_arg syntax extension for parsing command-line arguments

CAMLP4 syntax extension to offer a different interface to the Arg module for parsing command-line arguments.

Downloads

Documentation

usage:

type option [short|long|both] my_options = {
  fieldname : [param = value] *  fieldtype;
  ...
}

result:

type my_options = { ... }
parse_my_options: string (* usage *) -> my_options
print_my_options: my_options -> channel -> unit
parse_my_options: string (* usage *) -> unit

available params:

str=f       f takes an argument of the appropriate type and returns a string
            (otherwise print uses string_of_type or "user-specified data")
default=v   v is the default value of this field
            (otherwise the type is option'ed and the default is None)
spec=c      c is one of the Arg.spec constructors (as a string, without Arg.)
            (otherwise the spec is Int,Float,Unit,Bool,String, or Symbol 
             (see below) based on type)
arg=a       a is the argument of the spec
            (otherwise the spec argument is a function to assign the field based
             on the arg, or the field itself if the spec is Set or Clear)
help=s      s is a help string
            (otherwise the help string is the spec + the name of the field)
key=s       s is the option key
            (otherwise the option key is "-" plus the first character of the
             field name* ) 

fieldname can be _ in which case an option is still generated, but no field in the record type. Obviously at least the `arg' and `key' parameters must be provided. Multiple such anonymous fields can be created in a single record.

*- The default for unspecified keys is that they be short: "-" plus the first character of the field name. You can instead specify that they be long ("--" plus the whole field name) or that both be available.

You can also create symbol types with:

type option my_symbol_type = Val0 | Val1 "string-for-val1" | ...

result:

type my_symbol_type = Val0 | ...
my_symbol_type_of_string: string -> my_symbol_type
string_of_my_symbol_type: my_symbol_type -> string

my_symbol_type can now be used in a type option record as above, in which case the Arg.Symbol spec will be used, with the allowable values being the lowercased versions of the type constructors (or the provided string, if given). The default spec arg is a function which converts the user's string to one of the type constructors and assigns it to the field.

Contributors Eric Breck wrote this syntax extension. Martin Jambon contributed the short|long|both option.

Version: $Revision: 1.1 $