Csv_tool_lib.Csv_paraminclude Csv_param_intf.Csv_parammodule Open_on_rhs_intf = Csv_param_intf.Open_on_rhs_intfinclude Open_on_rhs_intf.Sinclude module type of struct include Async.Command.Param endinclude sig ... endinclude module type of Command.Param
with module Arg_type := Command.Param.Arg_typemodule type S = Async.Command.Param.Stype +'a t = 'a Command.Param.tCommand.Param is intended to be used with the [%map_open] syntax defined in ppx_let, like so:
let command =
Command.basic
~summary:"..."
(let%map_open 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 =
let%map_open 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.
See example/command/main.ml for more examples.
include Base.Applicative.S with type 'a t := 'a tval return : 'a 'p 'q. 'a -> 'a tConvert a value to a t.
Applies the functions in one t to the values in another. Well-behaved applicatives satisfy these "laws", using <*> as infix apply:
return Fn.id <*> t is equivalent to treturn Fn.compose <*> tf <*> tg <*> tx is equivalent to tf <*> (tg <*> tx)return f <*> return x is equivalent to return (f x)tf <*> return x is equivalent to return (fun f -> f x) <*> tfCombines values in two ts as tuples. Using <*> as infix apply, equivalent to return (fun a b -> a, b) <*> ta <*> tb.
Transforms the contents of a t. Using <*> as infix apply, equivalent to return f <*> t.
Combines the contents of two ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb.
Combines the contents of three ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb <*> tc.
module Applicative_infix = Async.Command.Param.Applicative_infixval help : Base.string Base.Lazy.t tThe help text for the command.
val path : Base.string Base.list tThe subcommand path of the command.
val args : Base.string Base.list tThe arguments passed to the command.
val flag :
?aliases:Base.string Base.list ->
?full_flag_required:Base.unit ->
Base.string ->
'a Command.Flag.t ->
doc:Base.string ->
'a tflag 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_sexp :
?aliases:Base.string Base.list ->
?full_flag_required:Base.unit ->
Base.string ->
'a Command.Arg_type.t ->
('a -> Base.Sexp.t) ->
default:'a ->
doc:Base.string ->
'a tflag_optional_with_default_doc_sexp name arg_type sexp_of_default ~default ~doc is a shortcut for flag, where:
Flag.t is optional_with_default default arg_typedoc is passed through with an explanation of what the default value appended.val flag_optional_with_default_doc_string :
?aliases:Base.string Base.list ->
?full_flag_required:Base.unit ->
Base.string ->
'a Command.Arg_type.t ->
('a -> Base.string) ->
default:'a ->
doc:Base.string ->
'a tflag_optional_with_default_doc_string name arg_type string_of_default ~default ~doc is similar to flag_optional_with_default_doc_sexp but uses string_of_default rather than converting via sexp.
val anon : 'a Command.Anons.t -> 'a tanon spec specifies a command that, among other things, takes the anonymous arguments specified by spec.
val escape_anon :
final_anon:'a Command.Anons.t ->
('a * Base.string Base.list) tescape_anon ~final_anon parses anon and then stops parsing. Remaining command line arguments are collected in the string list, even if they start with dashes.
See escape for the flag version of this behavior.
The final anon is required to indicate when to stop parsing.
module If_nothing_chosen = Async.Command.Param.If_nothing_chosenval choose_one :
'a Base.option t Base.list ->
if_nothing_chosen:('a, 'b) If_nothing_chosen.t ->
'b tchoose_one clauses ~if_nothing_chosen expresses a sum type. It raises if more than one of clauses is Some _. When if_nothing_chosen = Raise, it also raises if none of clauses is Some _.
val choose_one_non_optional :
'a t Base.list ->
if_nothing_chosen:('a, 'b) If_nothing_chosen.t ->
'b tchoose_one_non_optional clauses ~if_nothing_chosen expresses a sum type. It raises if more than one of the clauses has any flags given on the command-line, and returns the value parsed from the clause that's given.
When if_nothing_chosen = Raise, it also raises if none of the clauses are given.
val and_arg_names : 'a t -> ('a * Base.string Base.list) tand_arg_names t returns both the value of t and the names of the arguments that went into t. Useful for errors that reference multiple params.
val and_arg_name : 'a t -> ('a * Base.string) tLike and_arg_names, but asserts that there is exactly one name.
val arg_names : 'a t -> Base.string Base.listval optional_to_required : 'a Base.option t -> 'a tIf None is returned, then the param acts as a required flag that was omitted. This is intended to be used with choose_one_non_optional.
Values included for convenience so you can specify all command line parameters inside a single local open of Param.
include module type of Command.Param.Arg_type.Exportinclude module type of Command.Flag with type 'a t := 'a Command.Flag.tval required : 'a Command.Arg_type.t -> 'a Command.Flag.tRequired flags must be passed exactly once.
val optional : 'a Command.Arg_type.t -> 'a Base.option Command.Flag.tOptional flags may be passed at most once.
val optional_with_default : 'a -> 'a Command.Arg_type.t -> 'a Command.Flag.toptional_with_default flags may be passed at most once, and default to a given value.
val listed : 'a Command.Arg_type.t -> 'a Base.list Command.Flag.tlisted flags may be passed zero or more times.
val one_or_more_as_pair :
'a Command.Arg_type.t ->
('a * 'a Base.list) Command.Flag.tone_or_more_as_pair flags must be passed one or more times.
val one_or_more_as_list : 'a Command.Arg_type.t -> 'a Base.list Command.Flag.tLike one_or_more_as_pair, but returns the flag values as a list.
val no_arg : Base.bool Command.Flag.tno_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 Univ_map.With_default.Key.t ->
value:'a ->
Base.bool Command.Flag.tno_arg_register ~key ~value is like no_arg, but associates value with key in the autocomplete environment.
val no_arg_some : 'a -> 'a Base.option Command.Flag.tno_arg_some value is like no_arg, but will return Some value if the flag is passed on the command line, and return None otherwise.
val no_arg_required : 'a -> 'a Command.Flag.tno_arg_required value is like no_arg, but the argument is required. This is useful in combination with choose_one_non_optional.
val no_arg_abort :
exit:(Base.unit -> Base.Nothing.t) ->
Base.unit Command.Flag.tno_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 : Base.string Base.list Base.option Command.Flag.tescape 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 "--".
val escape_with_autocomplete :
complete:Command.Auto_complete.For_escape.t ->
Base.string Base.list Base.option Command.Flag.tval map_flag : 'a Command.Flag.t -> f:('a -> 'b) -> 'b Command.Flag.tmap_flag flag ~f transforms the parsed result of flag by applying f.
include module type of Command.Anons with type 'a t := 'a Command.Anons.tval (%:) : Base.string -> 'a Command.Arg_type.t -> 'a Command.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.
val sequence : 'a Command.Anons.t -> 'a Base.list Command.Anons.tsequence anons specifies a sequence of anonymous arguments. An exception will be raised if anons matches anything other than a fixed number of anonymous arguments.
val non_empty_sequence_as_pair :
'a Command.Anons.t ->
('a * 'a Base.list) Command.Anons.tnon_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.
val non_empty_sequence_as_list :
'a Command.Anons.t ->
'a Base.list Command.Anons.tval maybe : 'a Command.Anons.t -> 'a Base.option Command.Anons.t(maybe anons) indicates that some anonymous arguments are optional.
val maybe_with_default : 'a -> 'a Command.Anons.t -> 'a Command.Anons.t(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))val t2 : 'a Command.Anons.t -> 'b Command.Anons.t -> ('a * 'b) Command.Anons.tval t3 :
'a Command.Anons.t ->
'b Command.Anons.t ->
'c Command.Anons.t ->
('a * 'b * 'c) Command.Anons.tval t4 :
'a Command.Anons.t ->
'b Command.Anons.t ->
'c Command.Anons.t ->
'd Command.Anons.t ->
('a * 'b * 'c * 'd) Command.Anons.tval map_anons : 'a Command.Anons.t -> f:('a -> 'b) -> 'b Command.Anons.tmap_anons anons ~f transforms the parsed result of anons by applying f.
val parse : 'a t -> Base.string Base.list -> 'a Base.Or_error.tparse t cmdline will attempt to parse t out of cmdline. Beware there is nothing stopping effectful operations in t from being performed.
module Arg_type = Async.Command.Param.Arg_typeinclude module type of struct include Arg_type.Export endinclude module type of struct include Command.Arg_type.Export endval string : Base.string Command.Arg_type.tval int : Base.int Command.Arg_type.tBeware 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 : Base.char Command.Arg_type.tval float : Base.float Command.Arg_type.tval bool : Base.bool Command.Arg_type.tval sexp : Base.Sexp.t Command.Arg_type.tval sexp_conv :
?complete:(Univ_map.t -> part:Base.string -> Base.string Base.list) ->
(Base.Sexp.t -> 'a) ->
'a Command.Arg_type.tval date : Core.Date.t Command.Arg_type.tval percent : Core.Percent.t Command.Arg_type.tval host_and_port : Core.Host_and_port.t Command.Arg_type.tval file_stdin_anon : Csv_common.Or_file.t tval file_stdin_flag : Csv_common.Or_file.t tval files : string list tval reverse : bool tval reverse_fields : string list tval field : string tval field' : aliases:string list -> string tval time_field : string tval start_time : Core.Time_float.t tval stop_time : Core.Time_float.t tval grid_step : Core.Time_float.Span.t tval max_width : int option tval prefer_split_on_spaces : bool tval regexp_arg : Re2.t Arg_type.tval invert : bool tval skip_lines : int option tval sep_arg : char Arg_type.tval sep : char tval key_specifier : string tval no_header : bool tval no_headers_use_indices_instead : bool tval space : int tval suppress_header : bool tval utf8 : bool tval fields_gen : doc:string -> string list tval fields : string list tval fields_backward_compat : string list tval pop_fields : string list tval exclude_fields : bool tval table_attrs : (string * string option) list tval th_attrs : (string * string option) list tval tr_attrs : (string * string option) list tval td_attrs : (string * string option) list tval border : bool tinclude Core.Applicative.Let_syntax
with type 'a t := 'a Async.Command.Param.t
with module Open_on_rhs_intf := Open_on_rhs_intfmodule Let_syntax : sig ... end