Posix_getoptPOSIX command-line option parsing bindings.
This module provides OCaml bindings to the POSIX getopt functions defined in unistd.h.
It supports short options (single character), long options (GNU extension), and various argument handling modes.
Long option: a pair of (long name, short equivalent). For example, ("verbose", 'v') matches both --verbose and -v.
Argument specification for an option.
`None f - Option takes no argument. f () is called when matched.`Optional f - Option has an optional argument. f (Some arg) or f None.`Required f - Option requires an argument. f arg is called with the value.Option specification combining name and argument handler.
true if the system supports getopt_long_only (long options with single dash).
Enable or disable error messages printed to stderr by getopt. Default is true (errors are printed).
Reset the getopt state for parsing a new set of arguments. Call this before parsing a new argv if you've already parsed arguments.
Parse command-line arguments using short options only.
See getopt(3).
Example:
let verbose = ref false in
let output = ref "out.txt" in
let opts = [
{ name = 'v'; arg = `None (fun () -> verbose := true) };
{ name = 'o'; arg = `Required (fun s -> output := s) };
] in
let args = getopt Sys.argv opts in
(* args contains non-option arguments *)Parse command-line arguments using long options (GNU extension).
See getopt_long(3).
Long options are specified as --name or --name=value. Each long option also has a short equivalent.
Like getopt_long but also accepts long options with a single dash.
For example, -verbose is treated the same as --verbose.