DEPRECATED: use Core.Std.Command instead
command-line parsing with hierarchical sub-commands
exception Invalid_arguments of string list
module Flag : sig .. end
type 'a t
type of flags to a command with accumulator type 'a
val name : 'a t -> string
type ('a, 'b) create = string ->
?aliases:string list -> ?full_flag_required:bool -> 'b -> doc:string -> 'a t
Template for flag-creation functions
val of_arg : Core.Std.Arg.t -> unit t
Flag handling without an accumulator
val noarg : (unit, unit -> unit) create
val string : (unit, string -> unit) create
val int : (unit, int -> unit) create
val float : (unit, float -> unit) create
val bool : (unit, bool -> unit) create
val gen : (string -> 'gen) -> (unit, 'gen -> unit) create
val set_string : (unit, string ref) create
val set_string_opt : (unit, string option ref) create
val set_int : (unit, int ref) create
val set_int_opt : (unit, int option ref) create
val set_float : (unit, float ref) create
val set_float_opt : (unit, float option ref) create
val set_date : (unit, Core.Std.Date.t ref) create
val set_date_opt : (unit, Core.Std.Date.t option ref) create
val set : (unit, bool ref) create
val clear : (unit, bool ref) create
val set_gen : (string -> 'gen) -> (unit, 'gen ref) create
val set_gen_opt : (string -> 'gen) -> (unit, 'gen option ref) create
flag handling meant for use with immutable accumulator
val noarg_acc : ('a, 'a -> 'a) create
val string_acc : ('a, 'a -> string -> 'a) create
val int_acc : ('a, 'a -> int -> 'a) create
val bool_acc : ('a, 'a -> bool -> 'a) create
val float_acc : ('a, 'a -> float -> 'a) create
val date_acc : ('a, 'a -> Core.Std.Date.t -> 'a) create
rest f: a flag that signals the end of flag processing. all remaining arguments are passed to the f
val rest_acc : ('a, 'a -> string list -> 'a) create
val gen_acc : (string -> 'gen) -> ('a, 'a -> 'gen -> 'a) create
flag handling meant for use with mutable accumulator
val noarg_mut : ('a, 'a -> unit) create
val arg_mut : ('a, 'a -> string -> unit) create
val string_mut : ('a, 'a -> string -> unit) create
val int_mut : ('a, 'a -> int -> unit) create
val bool_mut : ('a, 'a -> bool -> unit) create
val float_mut : ('a, 'a -> float -> unit) create
val date_mut : ('a, 'a -> Core.Std.Date.t -> unit) create
rest f: a flag that signals the end of flag processing. all remaining arguments are passed to the f
val rest_mut : ('a, 'a -> string list -> unit) create
val gen_mut : (string -> 'gen) -> ('a, 'a -> 'gen -> unit) create
module Action : sig .. end

Deprecated

This is the old deprecated interface to Flag
type 'accum t
'accum-mutating action to perform when processing a flag
val noarg : ('accum -> unit) -> 'accum t
an action for a flag that takes no additional argument
val arg : ('accum -> string -> unit) -> 'accum t
an action for a flag that takes an additional string argument
val rest : ('accum -> string list -> unit) -> 'accum t
rest f: an action for a flag that signals the end of flag processing. all remaining arguments are passed to the f
rest f: an action for a flag that signals the end of flag processing. all remaining arguments are passed to the f
val int : ('accum -> int -> unit) -> 'accum t
an action for a flag that takes an additional int argument
val bool : ('accum -> bool -> unit) -> 'accum t
an action for a flag that takes an additional bool argument
val float : ('accum -> float -> unit) -> 'accum t
an action for a flag that takes an additional float argument
val create : ?aliases:string list ->
?full_flag_required:bool -> name:string -> doc:string -> 'a Action.t -> 'a t
val lift : 'a t -> project:('b -> 'a * ('a -> 'b)) -> 'b t
lift t ~project transforms a flag with accumulator type 'a into a flag with a more informative accumulator type 'b provided that project x returns a pair consisting of 1. a 'a-value extracted from the 'b-value x, and 2. a function for rebuilding a modified 'b-value from the modified 'a-value resulting from processing the flag.

The intended use pattern for lift is when 'b is a record type with a field foo of type 'a and project is fun r -> (r.foo, (fun foo' -> { r with foo = foo' }))

val lift_unit : unit t -> 'any t
val to_spec : ('accum -> 'accum) ref -> 'accum t -> ('c, 'c) Core.Std.Command.Spec.t
val to_spec_unit : unit t -> ('c, 'c) Core.Std.Command.Spec.t
val to_spec_units : unit t list -> ('c, 'c) Core.Std.Command.Spec.t
module Shared_flags : sig .. end
type 'a t = {
flags : unit Flag.t list;
get : unit -> 'a;
}
type t
module Autocomplete : sig .. end
type t = string list -> string list
module Bash_action : sig .. end
type t = [ `Alias
| `Arrayvar
| `Binding
| `Builtin
| `Command
| `Directory
| `Disabled
| `Enabled
| `Export
| `File
| `Function
| `Group
| `Helptopic
| `Hostname
| `Job
| `Keyword
| `Running
| `Service
| `Setopt
| `Shopt
| `Signal
| `Stopped
| `User
| `Variable ]
val bash : Bash_action.t list -> t
create actions command_line gets the completion suggestions that bash's compgen would generate for the selected actions and the last word of the command_line.
create ~autocomplete ~summary ~usage_arg ~init ~flags ~final main constructs a base command from the following data:
  • 'accum a mutable accumulator type for gathering arguments
  • 'args a composite argument type for the command, build from 'accum
  • autocomplete an optional argument defining a bash autocompletion function for the base command.
  • summary a short description of what the command does
  • readme a longer description of what the command does
  • usage_arg an abbreviation of the arguments it expects
  • init a function that creates an mutable accumulator of type 'accum
  • flags a list of command line flags together with their associated accumulator-mutating actions
  • final a function that constructs the final argument structure of type 'args from the accumulated arguments. The second argument to the function is the list of all annonymous arguments. This function should raise an exception with some explanation if it is unable to construct a complete value of type 'args.
  • help an optional function that will be called to generate help for a command instead of the standard help
  • main the main function, parameterized by the argument structure
val create : ?autocomplete:Autocomplete.t ->
?readme:(unit -> string) ->
summary:string ->
usage_arg:string ->
init:(unit -> 'accum) ->
flags:'accum Flag.t list ->
final:('accum -> string list -> 'argv) -> ('argv -> unit) -> t
val create0 : ?autocomplete:Autocomplete.t ->
?readme:(unit -> string) ->
summary:string ->
usage_arg:string ->
init:(unit -> 'accum) ->
flags:'accum Flag.t list -> final:('accum -> 'args) -> ('args -> unit) -> t
val create_no_accum : ?autocomplete:Autocomplete.t ->
?readme:(unit -> string) ->
summary:string ->
usage_arg:string ->
flags:unit Flag.t list ->
final:(string list -> 'args) -> ('args -> unit) -> t
val create_no_accum0 : ?autocomplete:Autocomplete.t ->
?readme:(unit -> string) ->
summary:string ->
usage_arg:string -> flags:unit Flag.t list -> (unit -> unit) -> t
val group : summary:string -> ?readme:(unit -> string) -> (string * t) list -> t
group ~summary [...; (name_i, t_i); ...] is an aggregate command that dispatches to one of the named sub-commands. A "help" sub-command will also be generated for the group.

The name cannot contain underscores, however passing allow_underscores=true into run will parse underscores as dashes on the command line.

type 'a with_run_flags = ?version:string ->
?build_info:string ->
?argv:string list ->
?allow_unknown_flags:bool ->
?allow_underscores:bool ->
?hash_bang_expand:bool ->
?post_parse:([ `Error | `Help | `Ok ] -> string list -> unit) -> t -> 'a
val run : unit with_run_flags
val get_expanded_argv : unit -> string list
val get_expanded_cmdline : unit -> string
module Version : sig .. end
val command : ?version:string -> ?build_info:string -> unit -> t
Provides a "version" subcommand.
val print_version : ?version:string -> unit -> unit
module Annotated_field : sig .. end
This module is intended to help in using pa_fields to easily generate Command.t's when you have a record type each field of which you would like specified as a command line argument.

An example is as follows:

module M = struct
  type t = {
    field1 : int;
    field2 : float;
    field3 : bool;
    field4 : string option;
  } with fields

  module A = Annotated_field

  let ann_fields = Fields.fold ~init:[]
    ~field1:(A.required ~doc:" documentation for field1")
    ~field2:(A.default 1.0 string_of_float ~doc:" documentation for field2")
    ~field3:(A.set ~doc:" documentation for field3")
    ~field4:(A.optional ~doc:" documentation for field4")

  let command = create
    ~summary:"summary"
    ~init:(fun () -> A.init ann_fields)
    ~usage_arg:""
    ~flags:(List.map ann_fields ~f:A.to_flag)
    ~final:(fun accum _anon_args ->
      let get of_string = A.get accum of_string in
      let get_opt of_string = A.get_opt accum of_string in
      Fields.map
        ~field1:(get int_of_string)
        ~field2:(get Float.of_string)
        ~field3:(get bool_of_string)
        ~field4:(get_opt ident)
    )
    ~main:(fun _ -> assert false)
end
type t
type accum
val required : ?name:string -> t list -> doc:string -> ('a, 'b) Fieldslib.Field.t -> t list
val default : ?name:string ->
'field ->
('field -> string) ->
t list -> doc:string -> ('a, 'field) Fieldslib.Field.t -> t list
val optional : ?name:string ->
?suppress_word_optional:bool ->
t list -> doc:string -> ('a, 'b option) Fieldslib.Field.t -> t list
val set : ?name:string ->
t list -> doc:string -> ('a, bool) Fieldslib.Field.t -> t list
val clear : ?name:string ->
t list -> doc:string -> ('a, bool) Fieldslib.Field.t -> t list
val list : ?name:string ->
t list -> doc:string -> ('a, 'b list) Fieldslib.Field.t -> t list
val init : t list -> accum
val to_flag : t -> accum Flag.t
val get : accum -> (string -> 'field) -> ('a, 'field) Fieldslib.Field.t -> 'field
val get_opt : accum ->
(string -> 'field) -> ('a, 'field option) Fieldslib.Field.t -> 'field option
val get_list : accum ->
(string -> 'field) -> ('a, 'field list) Fieldslib.Field.t -> 'field list
module Flags_ext : sig .. end
type 'a setter = 
|No_arg of 'a
|Arg of string -> 'a
type ('a, 'flag) t
val flag : ('a, 'flag) t -> 'flag
val get : ('a, 'b) t -> 'a
val is_set : ('a, 'b) t -> bool
val create_optional : name:string -> doc:string -> 'a setter -> ('a option, unit Flag.t) t
val create : ?default:'a * ('a -> string) ->
name:string -> doc:string -> 'a setter -> ('a, unit Flag.t) t
val create_many : ?at_least_one:bool ->
name:string -> doc:string -> 'a setter -> ('a list, unit Flag.t) t
val create_choice : ?default:'a * ('a -> string) ->
(string * string * 'a setter) list -> ('a, unit Flag.t list) t
val create_choice_optional : (string * string * 'a setter) list -> ('a option, unit Flag.t list) t
val create_set : name:string -> doc:string -> (bool, unit Flag.t) t
val create_rest : ?name:string -> doc:string -> unit -> (string list option, unit Flag.t) t
module Helpers : sig .. end
exception Found_anonymous_arguments
val no_anons : 'a -> string list -> 'a
val of_core_command : Core.Std.Command.t -> t