Module Command.Param
Command-line parameter specification.
This module replaces Command.Spec, and should be used in all new code. Its types and compositional rules are much easier to understand.
module type S = sig ... endinclude 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__.Import.Applicative.S with type 'a t := 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b tval map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c tval map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd tval all : 'a t list -> 'a list tval all_unit : unit t list -> unit t
module Applicative_infix : Base__.Applicative_intf.Applicative_infix with type 'a t := 'a tVarious internal values
val help : Core_kernel__.Import.string Core_kernel.Lazy.t tThe help text for the command.
val path : Core_kernel__.Import.string Core_kernel__.Import.list tThe subcommand path of the command.
val args : Core_kernel__.Import.string Core_kernel__.Import.list tThe arguments passed to the command.
val flag : ?aliases:Core_kernel__.Import.string Core_kernel__.Import.list -> ?full_flag_required:Core_kernel__.Import.unit -> Core_kernel__.Import.string -> 'a Flag.t -> doc:Core_kernel__.Import.string -> 'a tflag name spec ~docspecifies a command that, among other things, takes a flag namednameon its command line.docindicates the meaning of the flag.All flags must have a dash at the beginning of the name. If
nameis not prefixed by "-", it will be normalized to"-" ^ name.Unless
full_flag_requiredis used, one doesn't have to passnameexactly on the command line, but only an unambiguous prefix ofname(i.e., a prefix which is not a prefix of any other flag's name).NOTE: the
docfor a flag which takes an argument should be of the formarg_name ^ " " ^ descriptionwherearg_namedescribes the argument anddescriptiondescribes 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:Core_kernel__.Import.string Core_kernel__.Import.list -> ?full_flag_required:Core_kernel__.Import.unit -> Core_kernel__.Import.string -> 'a Arg_type.t -> ('a -> Core_kernel.Sexp.t) -> default:'a -> doc:Core_kernel__.Import.string -> 'a tflag_optional_with_default_doc name arg_type sexp_of_default ~default ~docis a shortcut forflag, where:- The
Flag.tisoptional_with_default default arg_type - The
docis passed through with an explanation of what the default value appended.
- The
val anon : 'a Anons.t -> 'a tanon specspecifies a command that, among other things, takes the anonymous arguments specified byspec.
module If_nothing_chosen : sig ... endval choose_one : 'a Core_kernel__.Import.option t Core_kernel__.Import.list -> if_nothing_chosen:('a, 'b) If_nothing_chosen.t -> 'b tchoose_one clauses ~if_nothing_chosenexpresses a sum type. It raises if more than one ofclausesisSome _. Whenif_nothing_chosen = `Raise, it also raises if none ofclausesisSome _.
val and_arg_names : 'a t -> ('a * Core_kernel__.Import.string Core_kernel__.Import.list) tand_arg_names treturns both the value oftand the names of the arguments that went intot. Useful for errors that reference multiple params.
val and_arg_name : 'a t -> ('a * Core_kernel__.Import.string) tLike
and_arg_names, but asserts that there is exactly one name.
module Arg_type : module type of Arg_type with type 'a Arg_type.t = 'a Arg_type.tinclude module type of Arg_type.Export
val string : Core_kernel__.Import.string Arg_type.tval int : Core_kernel__.Import.int Arg_type.tBeware that an anonymous argument of type
intcannot be specified as negative, as it is ambiguous whether -1 is a negative number or a flag. (The same applies tofloat,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 : Core_kernel__.Import.char Arg_type.tval float : Core_kernel__.Import.float Arg_type.tval bool : Core_kernel__.Import.bool Arg_type.tval date : Core_kernel.Date.t Arg_type.tval percent : Core_kernel.Percent.t Arg_type.tval host_and_port : Core_kernel.Host_and_port.t Arg_type.tval sexp : Core_kernel.Sexp.t Arg_type.tval sexp_conv : (Core_kernel.Sexp.t -> 'a) -> 'a Arg_type.t
include module type of Flag with type 'a Flag.t := 'a Flag.t
val required : 'a Arg_type.t -> 'a tRequired flags must be passed exactly once.
val optional : 'a Arg_type.t -> 'a Core_kernel__.Import.option tOptional flags may be passed at most once.
val optional_with_default : 'a -> 'a Arg_type.t -> 'a toptional_with_defaultflags may be passed at most once, and default to a given value.
val listed : 'a Arg_type.t -> 'a Core_kernel__.Import.list tlistedflags may be passed zero or more times.
val one_or_more : 'a Arg_type.t -> ('a * 'a Core_kernel__.Import.list) tone_or_moreflags must be passed one or more times.
val no_arg : Core_kernel__.Import.bool tno_argflags 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 -> Core_kernel__.Import.bool tno_arg_register ~key ~valueis likeno_arg, but associatesvaluewithkeyin the autocomplete environment.
val no_arg_some : 'a -> 'a Core_kernel__.Import.option tno_arg_some valueis likeno_arg, but will returnSome valueif the flag is passed on the command line, and returnNoneotherwise.
val no_arg_abort : exit:(Core_kernel__.Import.unit -> Core_kernel__.Std_internal.never_returns) -> Core_kernel__.Import.unit tno_arg_abort ~exitis likeno_arg, but aborts command-line parsing by callingexit. This flag type is useful for "help"-style flags that just print something and exit.
val escape : Core_kernel__.Import.string Core_kernel__.Import.list Core_kernel__.Import.option tescapeflags 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
escapeis"--".
include module type of Anons with type 'a Anons.t := 'a Anons.t
val (%:) : Core_kernel__.Import.string -> 'a Arg_type.t -> 'a t(name %: typ)specifies a required anonymous argument of typetyp.The
namemust not be surrounded by whitespace; if it is, an exn will be raised.If the
nameis surrounded by a special character pair (<>, {}, [] or (),)namewill remain as-is, otherwise,namewill be uppercased.In the situation where
nameis 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)
nameis mentioned in the generated help for the command.
val sequence : 'a t -> 'a Core_kernel__.Import.list tsequence anonsspecifies a sequence of anonymous arguments. An exception will be raised ifanonsmatches anything other than a fixed number of anonymous arguments.
val non_empty_sequence_as_pair : 'a t -> ('a * 'a Core_kernel__.Import.list) tnon_empty_sequence_as_pair anonsandnon_empty_sequence_as_list anonsare likesequence anonsexcept that an exception will be raised if there is not at least one anonymous argument given.
val non_empty_sequence_as_list : 'a t -> 'a Core_kernel__.Import.list tval maybe : 'a t -> 'a Core_kernel__.Import.option t(maybe anons)indicates that some anonymous arguments are optional.