This module is intended to help in using pa_fields to easily generate Command.t's when you have a record type each field of which you would like specified as a command line argument.
An example is as follows:
module M = struct
type t = {
field1 : int;
field2 : float;
field3 : bool;
field4 : string option;
} with fields
module A = Annotated_field
let ann_fields = Fields.fold ~init:[]
~field1:(A.required ~doc:" documentation for field1")
~field2:(A.default 1.0 string_of_float ~doc:" documentation for field2")
~field3:(A.set ~doc:" documentation for field3")
~field4:(A.optional ~doc:" documentation for field4")
let command = create
~summary:"summary"
~init:(fun () -> A.init ann_fields)
~usage_arg:""
~flags:(List.map ann_fields ~f:A.to_flag)
~final:(fun accum _anon_args ->
let get of_string = A.get accum of_string in
let get_opt of_string = A.get_opt accum of_string in
Fields.map
~field1:(get int_of_string)
~field2:(get Float.of_string)
~field3:(get bool_of_string)
~field4:(get_opt ident)
)
~main:(fun _ -> assert false)
end