package cmdlang
Module Command.ParamSource
Refer to the Parameters terminology.
type 'a of_string := string -> ('a, [ `Msg of string ]) resultParsing parameters of type 'a from the command line.
A type to hold the capability of parsing and printing a parameter of type 'a.
Printing parameters of type 'a is expected to roundtrip, thus using the syntax expected by the parsing function. Printing parameter is used for example when documenting default values in the help messages.
val create' :
docv:string ->
of_string:'a of_string ->
to_string:('a -> string) ->
unit ->
'a tCreate a param manually from the parameters and functions required to implement its capabilities.
val create_with_pp :
docv:string ->
parse:'a of_string ->
pp:(Format.formatter -> 'a -> unit) ->
unit ->
'a tAn alternative to create' where the printing it done through the use of a temporary formatter.
Basic types
The API supports basic types with default docv values. These defaults can be overridden for each argument. The default docv is used only if none is specified at the argument level. The actual syntax used by default depend on the targeted backend.
Helpers
Helpers for creating parameters for custom types. These helpers also come with default docv values, which can be overridden as needed.
Create a parameter for an enumerated type. The module must implement the Enumerated_stringable interface.
Example:
module Color = struct
type t =
| Red
| Green
| Blue
let all = [ Red; Green; Blue ]
let to_string = function
| Red -> "red"
| Green -> "green"
| Blue -> "blue"
;;
end
let color_param = Param.enumerated ~docv:"COLOR" (module Color)The usage message will show the supported values for COLOR.
To be used with custom types when the parsing may fail.
Deprecated
val create :
docv:string ->
parse:'a of_string ->
print:(Format.formatter -> 'a -> unit) ->
'a tThis is now available as create_with_pp. You may migrate your code by running ocamlmig migrate, or upgrade the call site to use instead the function create'. Note that in a future version, create will be removed and then reintroduced as the canonical name for what is now available with the name create'. This transition will be done in the course of several upgrades and migrations.