package genspio
Legend:
Library
Module
Module type
Parameter
Class
Class type
Library
Module
Module type
Parameter
Class
Class type
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
...
*)
type _ option_spec =
| Opt_flag : bool t cli_option -> bool t option_spec
| Opt_string : c_string t cli_option -> c_string t option_spec
and (_, _) cli_options =
| Opt_end : string -> ('a, 'a) cli_options
| Opt_cons : 'c option_spec * ('a, 'b) cli_options -> ('c -> 'a, 'b) cli_options
module Arg : sig ... end
val parse : ('a, unit t) cli_options -> (anon:c_string list t -> 'a) -> unit t
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>