async_extra
Library
Module
Module type
Parameter
Class
Class type
module type S = sig ... end
include S
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_kernel.Applicative.S with type 'a t := 'a t
val return : 'a -> 'a t
module Applicative_infix : sig ... end
Various internal values
val help : string Core_kernel.Lazy.t t
The help text for the command.
val path : string list t
The subcommand path of the command.
val args : string list t
The arguments passed to the command.
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.
val flag_optional_with_default_doc :
?aliases:string list ->
?full_flag_required:unit ->
string ->
'a Arg_type.t ->
( 'a -> Core_kernel.Sexp.t ) ->
default:'a ->
doc:string ->
'a t
flag_optional_with_default_doc name arg_type sexp_of_default ~default ~doc
is a shortcut for flag
, where:
- The
Flag.t
isoptional_with_default default arg_type
- The
doc
is passed through with an explanation of what the default value appended.
anon spec
specifies a command that, among other things, takes the anonymous arguments specified by spec
.
Values included for convenience so you can specify all command line parameters inside a single local open of Param
.
module Arg_type : module type of Arg_type with type 'a t = 'a Arg_type.t
include module type of Arg_type.Export
Values to include in other namespaces.
val string : string Arg_type.t
val int : int Arg_type.t
Beware that an anonymous argument of type int
cannot be specified as negative, as it is ambiguous whether -1 is a negative number or a flag. (The same applies to float
, time_span
, etc.) You can use the special built-in "-anon" flag to force a string starting with a hyphen to be interpreted as an anonymous argument rather than as a flag, or you can just make it a parameter to a flag to avoid the issue.
val char : char Arg_type.t
val float : float Arg_type.t
val bool : bool Arg_type.t
val date : Core__.Import.Date.t Arg_type.t
val percent : Core_kernel.Percent.t Arg_type.t
val time : Core_kernel.Time.t Arg_type.t
val time_ofday : Core__.Core_time_float.Ofday.Zoned.t Arg_type.t
Requires a time zone.
val time_ofday_unzoned :
Core_kernel.Core_kernel_private.Time_float0.underlying Arg_type.t
For when the time zone is implied.
val time_zone : Core_kernel__Zone.t Arg_type.t
val time_span : Core_kernel.Core_kernel_private.Time_float0.Span.t Arg_type.t
val file : string Arg_type.t
Uses bash autocompletion.
val host_and_port : Core_kernel.Host_and_port.t Arg_type.t
val ip_address : Unix.inet_addr Arg_type.t
val sexp : Core_kernel.Sexp.t Arg_type.t
val sexp_conv : ( Core_kernel.Sexp.t -> 'a ) -> 'a Arg_type.t
include module type of Flag with type 'a t := 'a Flag.t
Command-line flag specifications.
val required : 'a Arg_type.t -> 'a Flag.t
Required flags must be passed exactly once.
val optional : 'a Arg_type.t -> 'a option Flag.t
Optional flags may be passed at most once.
val optional_with_default : 'a -> 'a Arg_type.t -> 'a Flag.t
optional_with_default
flags may be passed at most once, and default to a given value.
val listed : 'a Arg_type.t -> 'a list Flag.t
listed
flags may be passed zero or more times.
val one_or_more : 'a Arg_type.t -> ('a * 'a list) Flag.t
one_or_more
flags must be passed one or more times.
val no_arg : bool Flag.t
no_arg
flags may be passed at most once. The boolean returned is true iff the flag is passed on the command line.
val no_arg_register :
key:'a Core_kernel.Univ_map.With_default.Key.t ->
value:'a ->
bool Flag.t
no_arg_register ~key ~value
is like no_arg
, but associates value
with key
in the autocomplete environment.
val no_arg_abort : exit:( unit -> Core_kernel.Nothing.t ) -> unit Flag.t
no_arg_abort ~exit
is like no_arg
, but aborts command-line parsing by calling exit
. This flag type is useful for "help"-style flags that just print something and exit.
val escape : string list option Flag.t
escape
flags may be passed at most once. They cause the command line parser to abort and pass through all remaining command line arguments as the value of the flag.
A standard choice of flag name to use with escape
is "--"
.
include module type of Anons with type 'a t := 'a Anons.t
Anonymous command-line argument specification.
val (%:) : string -> 'a Arg_type.t -> 'a Anons.t
(name %: typ)
specifies a required anonymous argument of type typ
.
The name
must not be surrounded by whitespace; if it is, an exn will be raised.
If the name
is surrounded by a special character pair (<>, {}, [] or (),) name
will remain as-is, otherwise, name
will be uppercased.
In the situation where name
is only prefixed or only suffixed by one of the special character pairs, or different pairs are used (e.g., "<ARG]"), an exn will be raised.
The (possibly transformed) name
is mentioned in the generated help for the command.
sequence anons
specifies a sequence of anonymous arguments. An exception will be raised if anons
matches anything other than a fixed number of anonymous arguments.
non_empty_sequence_as_pair anons
and non_empty_sequence_as_list anons
are like sequence anons
except that an exception will be raised if there is not at least one anonymous argument given.
(maybe anons)
indicates that some anonymous arguments are optional.
(maybe_with_default default anons)
indicates an optional anonymous argument with a default value.
t2
, t3
, and t4
each concatenate multiple anonymous argument specs into a single one. The purpose of these combinators is to allow for optional sequences of anonymous arguments. Consider a command with usage:
main.exe FOO [BAR BAZ]
where the second and third anonymous arguments must either both be there or both not be there. This can be expressed as:
t2 ("FOO" %: foo) (maybe (t2 ("BAR" %: bar) ("BAZ" %: baz)))]
Sequences of 5 or more anonymous arguments can be built up using nested tuples:
maybe (t3 a b (t3 c d e))