package core_kernel

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Anonymous command-line argument specification.

A specification of some number of anonymous arguments.

type +'a t
val (%:) : Base.String.t -> '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 Base.List.t 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_as_pair : 'a t -> ('a * 'a Base.List.t) t

non_empty_sequence_as_pair anons and non_empty_sequence_as_list anons are like sequence anons except that an exception will be raised if there is not at least one anonymous argument given.

val non_empty_sequence_as_list : 'a t -> 'a Base.List.t t
val maybe : 'a t -> 'a Base.Option.t 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
val map_anons : 'a t -> f:('a -> 'b) -> 'b t

map_anons anons ~f transforms the parsed result of anons by applying f.

OCaml

Innovation. Community. Security.