module Kwarg: sig
.. end
Command Line Argument Processing
val unmash : ?unmash_gnu:bool -> string list -> string list
unmash cmd line switches eg -abc becomes -a -b -c
Returns list of unmashed switches eg ["-z";"foo";"-a";"-b";"-c";"-x";"bar";"baz"]
unmash_gnu
: unmash GNU --style args too (default: false
)
val ungnu : string list -> string list
ungnu cmd line switches eg ["--abc=12"]
becomes ["--abc"; "12"]
Returns list of ungnu'd switches eg ["-z"; "--abc"; "69"; "--123"; "-x"]
switches
: list of switches eg ["-z"; "--abc=69"; "--123"; "-x"]
val foldargv : ?nullstdin:bool ->
?stdin:string ->
?argv:string array -> ?with0:bool -> ('a -> string -> 'a) -> 'a -> 'a
fold over Sys.argv
, taking the conventional meaning of Sys.argv.(0)
into account (i.e., skip it by default).
Returns the accumulator
nullstdin
: if true, then an empty argv
is considered to represent stdin, and the
value of stdin
is inserted into the empty array (default: false
)
stdin
: string value used to represent stdin (default: "-"
)
argv
: the array of filename arguments to process (default: Sys.argv
)
f
: function 'a -> string -> 'a
to apply
acc
: initial accumulator
val argvlist : unit -> string list
Return Sys.argv
as a list, less Sys.argv.(0)
Getopt
A purely-applicative getopt that differs from (some) others (e.g. Arg
) in that:
- it's purely applicative
- it generates help /usage text for you
- it works on any string list (
Sys.argv
isn't hard-wired)
exception Syntax of string
exception Unset of string
exception Undefined of string
exception NYI
val syntax : ('a, unit, string, 'b) Pervasives.format4 -> 'a
module Valid: sig
.. end
val one : ('a -> 'b) -> 'a list -> 'b
val all : ('a -> bool) -> 'a list -> bool
val no : ('a -> bool) -> 'a list -> bool
type
rep =
| |
Set |
| |
One of string option |
| |
Any of string list |
| |
N of (int * string list) |
type
spec = {
|
name : string ; |
|
short : string ; |
|
long : string ; |
|
rep : rep ; |
|
valid : string list -> bool ; |
|
meta : string ; |
|
text : string ; |
}
val spec : spec
val shortopts : spec list -> string
val opt_get : (string, 'a) Hashtbl.t -> string -> 'a
val opt_get1 : (string, 'a list) Hashtbl.t -> string -> 'a
val opt_set : (string, 'a list) Hashtbl.t -> string -> bool
val help : spec list -> string list
val getopt : ?size:int ->
spec list ->
string list -> (string, string list) Hashtbl.t * string list