Up

Module Anons

anonymous argument specifications

Signature

type +'a t

a specification of some number of anonymous arguments

val (%:) : string -> 'a Arg_type.t -> 'a t

(name %: typ) specifies a required anonymous argument of type typ.

The name must not be surrounded by whitespace, if it is, an exn will be raised.

If the name is surrounded by a special character pair (<>, {}, [] or (),) name will remain as-is, otherwise, name will be uppercased.

In the situation where name is only prefixed or only suffixed by one of the special character pairs, or different pairs are used, (e.g. "<ARG") an exn will be raised.

The (possibly transformed) name is mentioned in the generated help for the command.

val sequence : 'a t -> 'a list t

sequence anons specifies a sequence of anonymous arguments. An exception will be raised if anons matches anything other than a fixed number of anonymous arguments

val non_empty_sequence : 'a t -> ('a * 'a list) t

non_empty_sequence anons is like sequence anons except an exception will be raised if there is not at least one anonymous argument given.

val maybe : 'a t -> 'a option t

(maybe anons) indicates that some anonymous arguments are optional

val maybe_with_default : 'a -> 'a t -> 'a t

(maybe_with_default default anons) indicates an optional anonymous argument with a default value

t2, t3, and t4 each concatenate multiple anonymous argument specs into a single one. The purpose of these combinators is to allow for optional sequences of anonymous arguments. Consider a command with usage:

        main.exe FOO [BAR BAZ]
       

where the second and third anonymous arguments must either both be there or both not be there. This can be expressed as:


        t2 ("FOO" %: foo) (maybe (t2 ("BAR" %: bar) ("BAZ" %: baz)))]
       

Sequences of 5 or more anonymous arguments can be built up using nested tuples:


        maybe (t3 a b (t3 c d e))
      
val t2 : 'a t -> 'b t -> ('a * 'b) t
val t3 : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
val t4 : 'a t -> 'b t -> 'c t -> 'd t -> ('a * 'b * 'c * 'd) t