Up

Module Param

This module is meant to eventually replace Command.Spec, because the types are easier to understand.

Signature

module type S = sig .. end
include S
type +'a t
include Core_kernel.Std.Applicative.S with type 'a t := 'a t
type 'a t
val return : 'a -> 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val map : 'a t -> f:('a -> 'b) -> 'b t
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
val map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
val all : 'a t list -> 'a list t
val both : 'a t -> 'b t -> ('a * 'b) t
module Applicative_infix : sig .. end
include module type of Applicative_infix
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

same as apply

val (<*) : 'a t -> unit t -> 'a t

same as apply

val (*>) : unit t -> 'a t -> 'a t

various internal values

val help : string Core_kernel.Std.Lazy.t t

the help text for the command

val path : string list t

the help text for the command

the subcommand path of the command

val args : string list t

the subcommand path of the command

the arguments passed to the command

val flag : ?aliases:string list -> ?full_flag_required:unit -> string -> 'a Flag.t -> doc:string -> 'a t

flag name spec ~doc specifies a command that, among other things, takes a flag named name on its command line. doc indicates the meaning of the flag.

All flags must have a dash at the beginning of the name. If name is not prefixed by "-", it will be normalized to "-" ^ name.

Unless full_flag_required is used, one doesn't have to pass name exactly on the command line, but only an unambiguous prefix of name (i.e., a prefix which is not a prefix of any other flag's name).

NOTE: the doc for a flag which takes an argument should be of the form arg_name ^ " " ^ description where arg_name describes the argument and description describes the meaning of the flag.

NOTE: flag names (including aliases) containing underscores will be rejected. Use dashes instead.

NOTE: "-" by itself is an invalid flag name and will be rejected.

val anon : 'a Anons.t -> 'a t

anon spec specifies a command that, among other things, takes the anonymous arguments specified by spec.

val choose_one : 'a option t list -> if_nothing_chosen:[
| `Default_to of 'a
| `Raise
] -> 'a t

choose_one clauses ~if_nothing_chosen expresses a sum type. It raises if more than one of clauses is Some _. When if_nothing_chosen = `Raise, it also raises if none of clauses is Some _.

module Arg_type : module type of Arg_type with type 'a t = 'a Arg_type.t
include module type of Arg_type.Export
val string : string Arg_type.t

Beware that an anonymous argument of type int cannot be specified as negative, as it is ambiguous whether -1 is a negative number or a flag. If you need to pass a negative number to your program, make it a parameter to a flag.

val int : int Arg_type.t

Beware that an anonymous argument of type int cannot be specified as negative, as it is ambiguous whether -1 is a negative number or a flag. If you need to pass a negative number to your program, make it a parameter to a flag.

val char : char Arg_type.t
val float : float Arg_type.t
val bool : bool Arg_type.t

time requires a time zone.

time requires a time zone.

Use time_ofday_unzoned only when time zone is implied somehow.

val time_ofday_unzoned : Core.Time.Ofday.t Arg_type.t

Use time_ofday_unzoned only when time zone is implied somehow.

val time_zone : Core.Time.Zone.t Arg_type.t
val time_span : Core.Time.Span.t Arg_type.t
val file : string Arg_type.t
include module type of Flag with type 'a t := 'a Flag.t
type 'a t
val required : 'a Arg_type.t -> 'a t

required flags must be passed exactly once

val optional : 'a Arg_type.t -> 'a option t

optional flags may be passed at most once

val optional_with_default : 'a -> 'a Arg_type.t -> 'a t

optional_with_default flags may be passed at most once, and default to a given value

val listed : 'a Arg_type.t -> 'a list t

listed flags may be passed zero or more times

val one_or_more : 'a Arg_type.t -> ('a * 'a list) t

one_or_more flags must be passed one or more times

val no_arg : bool t

no_arg flags may be passed at most once. The boolean returned is true iff the flag is passed on the command line

val no_arg_register : key:'a Core_kernel.Std.Univ_map.With_default.Key.t -> value:'a -> bool t

no_arg_register ~key ~value is like no_arg, but associates value with key in the in the auto-completion environment

val no_arg_abort : exit:(unit -> Core_kernel.Std.never_returns) -> unit t

no_arg_abort ~exit is like no_arg, but aborts command-line parsing by calling exit. This flag type is useful for "help"-style flags that just print something and exit.

val escape : string list option t

escape flags may be passed at most once. They cause the command line parser to abort and pass through all remaining command line arguments as the value of the flag.

A standard choice of flag name to use with escape is "--".

include module type of Anons with type 'a t := 'a Anons.t
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