Module EDSL.Command_lineSource
Typed command-line parsing for your shell scripts, à la Printf.scanf.
Use this module like OCaml's Printf.scanf function.
- Build a command-line “format specification” using the
Arg module. - Call the
parse function with an appropriately typed function.
Example: Here is a potential argument specification for a shell script that downloads and unarchives them (see also "src/test/examples.ml").
let cli_spec =
Command_line.Arg.(
string
~doc:"The URL to the stuff" ["-u"; "--url"]
~default:no_value
& flag ["-d"; "--remove-intermediary-files"]
~doc:"Remove intermediary files."
& string ["-f"; "--local-filename"]
~doc:"Override the downloaded file-name"
~default:no_value
& string ["-t"; "--tmp-dir"]
~doc:"Use <dir> as temp-dir"
~default:(Genspio.EDSL.string "/tmp/genspio-downloader-tmpdir")
& usage "Download archives and decrypt/unarchive them.\n\
./downloader -u URL [-c] [-f <file>] [-t <tmpdir>]"
) in
(*
`cli_spec` has type:
(string Genspio.EDSL.t ->
bool Genspio.EDSL.t ->
string Genspio.EDSL.t -> string Genspio.EDSL.t -> unit Genspio.EDSL.t,
unit Genspio.EDSL.t)
Genspio.EDSL.Command_line.cli_options
so the action function (the second argument to parse) must have type:
anon:string list Genspio.EDSL.t ->
string Genspio.EDSL.t ->
bool Genspio.EDSL.t ->
string Genspio.EDSL.t ->
string Genspio.EDSL.t ->
unit Genspio.EDSL.t
*)
Command_line.parse cli_spec
(fun ~anon url all_in_tmp filename_ov tmp_dir ->
(*
...
your code
...
*)
Sourcetype 'a cli_option = {switches : string list;doc : string;default : 'a;
}