package climate

  1. Overview
  2. Docs

Module Climate.Arg_parserSource

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

Sourcetype 'a t

A parser of values of type 'a

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

Make a 'a print value from a to_string function

Sourcemodule Completion : sig ... end
Sourcetype '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.

Sourceval 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

Sourceval string : string conv
Sourceval int : int conv
Sourceval float : float conv
Sourceval bool : bool conv
Sourceval file : string conv

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

Sourceval 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.

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

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

Sourceval 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).

Sourceval 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).

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

The apply operator in the parlance of applicative functors.

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

Shorthand for apply.

Sourceval const : 'a -> 'a t

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

Sourceval unit : unit t

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

Sourceval argv0 : string t

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

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

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

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

Sourceval 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).

Sourceval 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).

Sourceval 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).

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

Parses all positional arguments.

Sourceval 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.

Sourceval 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.

Sourcemodule 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.