Command.Param
is intended to be used with the %map_open
syntax defined in
ppx_let
, like so:
let command =
Command.basic' ~summary:"..."
[%map_open
let count = anon ("COUNT" %: int)
and port = flag "port" (optional int) ~doc:"N listen on this port"
and person = person_param
in
(* ... command-line validation code, if any, goes here ... *)
fun () ->
(* the body of the command *)
do_stuff count port person
]
One can also use %map_open
to define composite command line parameters, like
person_param
in the previous snippet:
type person = { name : string; age : int }
let person_param : person Command.Param.t =
[%map_open
let name = flag "name" (required string) ~doc:"X name of the person"
and age = flag "age" (required int) ~doc:"N how many years old"
in
{name; age}
]
The right hand sides of %map_open
definitions have Command.Param
in scope.
Alternatively, you can say:
let open Foo.Let_syntax in
[%map_open
let x ...
]
if Foo
follows the same conventions as Command.Param
.
See example/command/main.ml for more examples.
include Core__.Import.Applicative.S with type a t := a t
val return : 'a ‑> 'a t
module Applicative_infix : sig ... end
val flag : ?aliases:string list ‑> ?full_flag_required:unit ‑> string ‑> 'a Flag.t ‑> doc:string ‑> 'a t
flag name spec ~doc
specifies a command that, among other things, takes a flag
named name
on its command line. doc
indicates the meaning of the flag.
All flags must have a dash at the beginning of the name. If name
is not prefixed
by "-", it will be normalized to "-" ^ name
.
Unless full_flag_required
is used, one doesn't have to pass name
exactly on the
command line, but only an unambiguous prefix of name
(i.e., a prefix which is not
a prefix of any other flag's name).
NOTE: the doc
for a flag which takes an argument should be of the form
arg_name ^ " " ^ description
where arg_name
describes the argument and
description
describes the meaning of the flag.
NOTE: flag names (including aliases) containing underscores will be rejected. Use dashes instead.
NOTE: "-" by itself is an invalid flag name and will be rejected.