package climate

  1. Overview
  2. Docs

A DSL for declaratively describing a program's command-line arguments

type 'a t

A parser of values of type 'a

type 'a parse = string -> ('a, [ `Msg of string ]) Stdlib.result
type 'a print = Stdlib.Format.formatter -> 'a -> unit
val to_string_print : ('a -> string) -> 'a print

Make a 'a print value from a to_string function

module Completion : sig ... end
type 'a conv = {
  1. parse : 'a parse;
  2. print : 'a print;
  3. default_value_name : string;
  4. completion : 'a Completion.t option;
}

Knows how to interpret strings on the command line as a particular type and how to format values of said type as strings. Define a custom _ conv value to implement a parser for a custom type.

val make_conv : parse:'a parse -> print:'a print -> ?default_value_name:string -> ?completion:'a Completion.t option -> unit -> 'a conv

Helper function for constructing '_ convs

val string : string conv
val int : int conv
val float : float conv
val bool : bool conv
val file : string conv

Similar to string except its default value name and completion is specialized for files.

val enum : ?default_value_name:string -> ?eq:('a -> 'a -> bool) -> (string * 'a) list -> 'a conv

enum values ~eq returns a conv for a concrete set of possible values of type 'a. The values and their names are given by the values argument and eq is used when printing values to tie a given value of type 'a to a name.

val string_enum : ?default_value_name:string -> string list -> string conv

string_enum values ~eq returns a conv for a concrete set of possible strings.

val pair : ?sep:char -> 'a conv -> 'b conv -> ('a * 'b) conv

pair ~sep a b returns a conv for a pair of values separated by the first occurance of sep (',' by default).

val list : ?sep:char -> 'a conv -> 'a list conv

pair ~sep a b returns a conv for a list of values separated by sep (',' by default).

val map : 'a t -> f:('a -> 'b) -> 'b t
val both : 'a t -> 'b t -> ('a * 'b) t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
val let+ : 'a t -> ('a -> 'b) -> 'b t
val and+ : 'a t -> 'b t -> ('a * 'b) t
val apply : ('a -> 'b) t -> 'a t -> 'b t

The apply operator in the parlance of applicative functors.

val ($) : ('a -> 'b) t -> 'a t -> 'b t

Shorthand for apply.

val const : 'a -> 'a t

A parser that ignores the command line and always yields the same value

val unit : unit t

A parser that takes no arguments and returns (), included for testing purposes

val argv0 : string t

A parser that resolves to the program name as it appeared on the command line.

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

Takes a parser of a list and returns a parser that yields the last element of the list. Raises a Parse_error.E if the list is empty.

val named_multi : ?desc:string -> ?value_name:string -> ?hidden:bool -> ?completion:'a Completion.t -> string list -> 'a conv -> 'a list t

A named argument that may appear multiple times on the command line.

val named_opt : ?desc:string -> ?value_name:string -> ?hidden:bool -> ?completion:'a Completion.t -> string list -> 'a conv -> 'a option t

A named argument that may appear at most once on the command line.

val named_with_default : ?desc:string -> ?value_name:string -> ?hidden:bool -> ?completion:'a Completion.t -> string list -> 'a conv -> default:'a -> 'a t

A named argument that may appear at most once on the command line. If the argument is not passed then a given default value will be used instead.

val named_req : ?desc:string -> ?value_name:string -> ?hidden:bool -> ?completion:'a Completion.t -> string list -> 'a conv -> 'a t

A named argument that must appear exactly once on the command line.

val flag_count : ?desc:string -> ?hidden:bool -> string list -> int t

A flag that may appear multiple times on the command line. Evaluates to the number of times the flag appeared.

val flag : ?desc:string -> string list -> bool t

A flag that may appear at most once on the command line.

val pos_opt : ?value_name:string -> ?completion:'a Completion.t -> int -> 'a conv -> 'a option t

pos_opt i conv declares an optional anonymous positional argument at position i (starting at 0).

val pos_with_default : ?value_name:string -> ?completion:'a Completion.t -> int -> 'a conv -> default:'a -> 'a t

pos_with_default i conv declares an optional anonymous positional argument with a default value at position i (starting at 0).

val pos_req : ?value_name:string -> ?completion:'a Completion.t -> int -> 'a conv -> 'a t

pos_req i conv declares a required anonymous positional argument at position i (starting at 0).

val pos_all : ?value_name:string -> ?completion:'a Completion.t -> 'a conv -> 'a list t

Parses all positional arguments.

val pos_left : ?value_name:string -> ?completion:'a Completion.t -> int -> 'a conv -> 'a list t

pos_left i conv parses all positional arguments at positions less than i.

val pos_right : ?value_name:string -> ?completion:'a Completion.t -> int -> 'a conv -> 'a list t

pos_right i conv parses all positional arguments at positions greater than i.

module Reentrant : sig ... end

Stripped down versions of some functions from the parent module for use in reentrant completion functions. None of the documentation arguments are present as there is no access to documentation for the parsers for these functions. Parsers that would fail when passed multiple times no longer fail under this condition, since any errors encountered during autocompletion will be ignored, and it's more useful to have these functions do something rather than nothing.

OCaml

Innovation. Community. Security.