package ez_cmdliner
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=a4aaa008bf2bf29189e3c66c9481aab5d2e12b20c0b769a484df5dc07d68961d
doc/ez_cmdliner/Ezcmd/V2/EZCMD/index.html
Module V2.EZCMDSource
Specification of Arguments
type spec = TYPES.Arg.spec = | Unit of unit -> unit| Bool of bool -> unit| Set_bool of bool ref| Set of bool ref| Clear of bool ref| String of string -> unit| Set_string of string ref| Int of int -> unit| Set_int of int ref| Float of float -> unit| Set_float of float ref| Symbol of string list * string -> unit| File of string -> unit| Anon of int * string -> unit| Anons of string list -> unit
Type spec specifies kinds and actions for every argument. It is close to the Arg.spec type in the standard library. One main difference with Arg.spec is that these arguments should only appear once on the command-line, otherwise cmdliner is going to complain.
Anonymous arguments are treated a bit differently. Anon(n,f) means the anonymous argument at position n (starting from position 0). Anons f means all the anonymous arguments, provided as a list of strings to f.
EZCMD.env ~docs ~doc var describes an environment variable var. doc is the man page information of the environment variable, defaults to "undocumented". docs is the title of the man page section in which the environment variable will be listed, it defaults to Manpage.s_environment.
In doc the documentation markup language can be used with following variables:
$(env), the value ofvar.- The variables mentioned in
info
val info :
?docs:string ->
?docv:string ->
?env:TYPES.env ->
?version:string ->
string ->
TYPES.infoEZCMD.info docs docv env doc defines information for an argument.
envdefines the name of an environment variable which is looked up for defining the argument if it is absent from the command line. See environment variables for details.docis the man page information of the argument. The documentation language can be used and the following variables are recognized:"$(docv)"the value ofdocv(see below)."$(opt)", one of the options ofnames, preference is given to a long one."$(env)", the environment var specified byenv(if any).
These functions can help with formatting argument values.
docvis for positional and non-flag optional arguments. It is a variable name used in the man page to stand for their value.docsis the title of the man page section in which the argument will be listed. For optional arguments this defaults toManpage.s_options. For positional arguments this defaults toManpage.s_arguments. However a positional argument is only listed if it has both adocanddocvspecified.
val sub :
string ->
doc:string ->
?args:TYPES.arg_list ->
?man:TYPES.block list ->
?version:string ->
(unit -> unit) ->
TYPES.subEZCMD.sub name action associates the action action with the subcommand name. This module supports only one level of sub-commands, unless you are using the MAKE functor. With the MAKE functor, subcommand names can contain spaces.
main functions
EZCMD.main sub can be used when there is only one command in the executable. Arguments are defined in the sub-command definition.
val main_with_subcommands :
name:string ->
?version:string ->
?default:TYPES.sub ->
doc:string ->
?man:TYPES.block list ->
?topics:(string * Cmdliner.Manpage.block list) list ->
?common_args:TYPES.arg_list ->
?argv:string array ->
TYPES.sub list ->
unitEZCMD.main_with_subcommands ~name ~doc subcommands parses the arguments and calls the action of the selected sub-command.
Multi-level subcommands
The functor MAKE can be used to define a main function, supporting multi-level sub-commands.
It takes a list of subcommands, defined for example with:
open Ezcmd.V2
module MAIN = EZCMD.MAKE(struct
...
end)
let cmd1 = (* define one sub-command *)
let files = ref [] in
EZCMD.sub
"parse this file" (* with spaces !! *)
(fun () ->
... (* action to perform after parsing options of the sub-command *)
)
~args:
[
[ "a"; "after" ],
EZCMD.String (fun s -> ... ),
EZCMD.info ~docv:"STRING" "I use this string";
[],
EZCMD.Anons (fun args -> ... ),
EZCMD.info ~docv:"FILE" "I use these arguments" ;
]
~doc: "..."
~man:[
`S "DESCRIPTION";
`Blocks [
`P "..."
];
]
let cmd2 = ...
let cmd3 = ...
let () = MAIN.main [ cmd1 ; cmd2 ; cmd3 ]Default options provided by this functor:
-v|--verbose: increase verbosity and backtraces-q|--quiet: set verbosity to 0--version: print M.version--about: print M.about--echo: print command with current argumentsrst: output a .rst file with all subcommands
Compatibility with Stdlib Arg
val parse :
?name:string ->
?version:string ->
?man:TYPES.block list ->
(string * TYPES.Arg.spec * string) list ->
(string -> unit) ->
string ->
unitEZCMD.parse is mostly equivalent to Stdlib Arg.parse
val translate :
?docs:string ->
(string * TYPES.Arg.spec * string) list ->
(string list * TYPES.Arg.spec * TYPES.info) listEZCMD.translate args can be used to provide a list of arguments, à la Arg.parse, to other EZCMD commands.
EZCMD.translate_anon f returns a specification that will call f on every anonymous argument.