DEPRECATED: use Core.Std.Command instead
command-line parsing with hierarchical sub-commands
type of flags to a command with accumulator type 'a
Template for flag-creation functions
rest f
: a flag that signals the end of flag processing. all remaining arguments
are passed to the f
rest f
: a flag that signals the end of flag processing. all remaining arguments
are passed to the f
This is the old deprecated interface to Flag
'accum
-mutating action to perform when processing a flag
an action for a flag that takes an additional string argument
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
an action for a flag that takes an additional int argument
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' }))
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 doesreadme
a longer description of what the command doesusage_arg
an abbreviation of the arguments it expectsinit
a function that creates an mutable
accumulator of type 'accum
flags
a list of command line flags together with their
associated accumulator-mutating actionsfinal
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 helpmain
the main function, parameterized by the argument structuregroup ~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.
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