package core

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type
type +'a t

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 Base.Applicative.S with type 'a t := 'a t
val return : 'a -> 'a t
val map : 'a t -> f:('a -> 'b) -> 'b t
val both : 'a t -> 'b t -> ('a * 'b) t
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t

same as apply

val (<*) : 'a t -> unit t -> 'a t
val (*>) : unit t -> 'a t -> 'a t
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
val map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
module Applicative_infix : sig ... end

Various internal values

The help text for the command.

The subcommand path of the command.

The arguments passed to the command.

val flag : ?aliases:Base.String.t Base.List.t -> ?full_flag_required:Base.Unit.t -> Base.String.t -> 'a Flag.t -> doc:Base.String.t -> '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:Base.String.t Base.List.t -> ?full_flag_required:Base.Unit.t -> Base.String.t -> 'a Arg_type.t -> ('a -> Sexp.t) -> default:'a -> doc:Base.String.t -> 'a t

flag_optional_with_default_doc name arg_type sexp_of_default ~default ~doc is a shortcut for flag, where:

  1. The Flag.t is optional_with_default default arg_type
  2. The doc is passed through with an explanation of what the default value appended.
val anon : 'a Anons.t -> 'a t

anon spec specifies a command that, among other things, takes the anonymous arguments specified by spec.

val escape_anon : final_anon:'a Anons.t -> ('a * Base.String.t Base.List.t) t

escape_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 : sig ... end
val choose_one : 'a Base.Option.t t Base.List.t -> if_nothing_chosen:('a, 'b) If_nothing_chosen.t -> 'b t

choose_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 and_arg_names : 'a t -> ('a * Base.String.t Base.List.t) t

and_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.t) t

Like and_arg_names, but asserts that there is exactly one name.

val arg_names : 'a t -> Base.String.t Base.List.t