package clim

  1. Overview
  2. Docs

Command Line Interface Maker

type 'a conv = 'a Cmdliner.Arg.conv

Converter type from Cmdliner.

type spec

Type flag meaning the argument isn't fully specified.

type final

Type flag meaning the argument is fully specified.

type ('a, 'b) arg

The argument type.


Flags are boolean values which don't need value: only their presence (true) or not (false) give their value.

val flag : ?docs:string -> ?doc:string -> ?env:string -> string list -> (bool, spec) arg

flag ~docs ~doc ~env aka defines a new flag whose names are given in aka.

Optional Arguments

Optional arguments are the usual argument specified by a -x or --xxx notation on command line.

val opt : ?docs:string -> ?docv:string -> ?doc:string -> ?env:string -> ?vopt:'a -> 'a conv -> 'a -> string list -> ('a, spec) arg

opt ~docs ~docv ~doc ~env ~vopt conv default aka defines a new optional argument whose names are given in aka.

val opt_all : ?docs:string -> ?docv:string -> ?doc:string -> ?env:string -> ?vopt:'a -> 'a conv -> 'a list -> string list -> ('a list, spec) arg

opt_all ~docs ~docv ~doc ~env ~vopt conv default aka same as opt but gathers several invocations of the options into a list. For example, this is useful for include directory options used in many tools.

Positional Arguments

Positional arguments have no name and are supposely mandatory and ordered on command line.

For now, positional arguments combinators are somehow illformed and will be modified in near future so use it carefuly.

val pos : ?docs:string -> ?docv:string -> ?doc:string -> ?env:string -> ?rev:bool -> 'a conv -> 'a -> int -> ('a, spec) arg
val pos_all : ?docs:string -> ?docv:string -> ?doc:string -> ?env:string -> 'a conv -> 'a list -> ('a list, spec) arg


To finalize an argument, the following constraints can be used.

val value : ('a, spec) arg -> ('a, final) arg

value a finalizes the argument a as itself.

val required : ('a option, spec) arg -> ('a, final) arg

required a ensures that argument a holding a optional value is given on command line.

val non_empty : ('a list, spec) arg -> ('a list, final) arg

non_empty a ensures that argument a holding a list is not empty.

val last : ('a list, spec) arg -> ('a, final) arg

last a ensures that only the last given value on command line will be used for a.


Configurations hold the command line argument to be used.

type cfg

Configuration type.

val create : unit -> cfg

Creates an empty configuration.

val from : cfg -> cfg

from cfg creates a new configuration based on cfg.

val register : cfg -> ('a, final) arg -> unit -> 'a

register cfg arg registers the argument arg info cfg and returns a getter to the option's value.


Since commands can have multiple related environment variable, we inherit their definitions from Cmdliner.

Environment variable specification type.

val env : ?docs:string -> ?doc:string -> string -> env

env ~docs ~doc name creates a ne environment variable specification named name.

type 'a command = {
  1. cfg : cfg;

    The related configuration.

  2. cmd : unit -> 'a;

    The command entrypoint.

  3. man_xrefs : Cmdliner.Manpage.xref list;

    Man references.

  4. man : Cmdliner.Manpage.block list;

    Additional man documentation.

  5. envs : env list;

    Environment variables.

  6. doc : string;

    Main documentation.

  7. version : string option;

    Version (if any).

  8. name : string;

    Binary name.


The command type. It gathers all Cmdliner related informations into one simle data structure.

val command : ?cfg:cfg -> ?man_xrefs:Cmdliner.Manpage.xref list -> ?man:Cmdliner.Manpage.block list -> ?envs:env list -> ?doc:string -> ?version:string option -> ?name:string -> (unit -> 'b) -> 'b command

Command maker.

term cmd returns the Cmdliner terms and info needed to use Cmdliner. This ensures some compatiblity with Cmdliner if defining a legacy Cmdliner command term.

val run : 'a command -> 'a

run cmd parses the command line according to the cmd specification and returns the result of the underlying function.

val bool : bool conv


The following converters are inherited from Cmdliner.

val char : char conv
val int : int conv
val nativeint : nativeint conv
val int32 : int32 conv
val int64 : int64 conv
val float : float conv
val string : string conv
val enum : (string * 'a) list -> 'a conv
val file : string conv
val dir : string conv
val non_dir_file : string conv
val option : ?none:string -> 'a conv -> 'a option conv
val list : ?sep:char -> 'a conv -> 'a list conv
val array : ?sep:char -> 'a conv -> 'a array conv
val pair : ?sep:char -> 'a conv -> 'b conv -> ('a * 'b) conv
val t2 : ?sep:char -> 'a conv -> 'b conv -> ('a * 'b) conv
val t3 : ?sep:char -> 'a conv -> 'b conv -> 'c conv -> ('a * 'b * 'c) conv
val t4 : ?sep:char -> 'a conv -> 'b conv -> 'c conv -> 'd conv -> ('a * 'b * 'c * 'd) conv
class virtual 'r cli : object ... end

The Object-Oriented CLI definition


Innovation. Community. Security.