5
exception Help of string
7
exception Bad of string
9
let not_implemented () =
10
failwith "Stdcompat.Arg is not fully implemented yet. Please fill an issue: https://github.com/thierry-martinez/stdcompat/issues ."
13
| Unit of (unit -> unit)
14
| Bool of (bool -> unit)
17
| String of (string -> unit)
18
| Set_string of string ref
19
| Int of (int -> unit)
21
| Float of (float -> unit)
22
| Set_float of float ref
24
| Symbol of string list * (string -> unit)
25
| Rest of (string -> unit)
26
| Expand of (string -> string array)
32
type usage_msg = string
34
type anon_fun = string -> unit
36
let rec no_expand spec =
38
| Unit f -> Arg.Unit f
39
| Bool f -> Arg.Bool f
41
| Clear c -> Arg.Clear c
42
| String f -> Arg.String f
43
| Set_string r -> Arg.Set_string r
45
| Set_int r -> Arg.Set_int r
46
| Float f -> Arg.Float f
47
| Set_float r -> Arg.Set_float r
48
| Tuple l -> Arg.Tuple (List.map no_expand l)
49
| Symbol (l, f) -> Arg.Symbol (l, f)
50
| Rest f -> Arg.Rest f
51
| Expand _ -> not_implemented ()
55
| Arg.Unit f -> Unit f
56
| Arg.Bool f -> Bool f
58
| Arg.Clear c -> Clear c
59
| Arg.String f -> String f
60
| Arg.Set_string r -> Set_string r
62
| Arg.Set_int r -> Set_int r
63
| Arg.Float f -> Float f
64
| Arg.Set_float r -> Set_float r
65
| Arg.Tuple l -> Tuple (List.map expand l)
66
| Arg.Symbol (l, f) -> Symbol (l, f)
67
| Arg.Rest f -> Rest f
69
let no_expand_list l =
70
List.map (fun (k, s, d) -> k, no_expand s, d) l
73
List.map (fun (k, s, d) -> k, expand s, d) l
76
let usage_string l msg =
77
Arg.usage_string (no_expand_list l) msg
80
let usage_string l msg =
86
expand_list (Arg.align (no_expand_list l))
93
let parse l anon msg =
94
Arg.parse (no_expand_list l) anon msg
96
let parse_argv ?current argv l anon msg =
97
Arg.parse_argv ?current argv (no_expand_list l) anon msg
100
Arg.usage (no_expand_list l) msg
102
let current = Arg.current
104
let read_aux trim sep file =
105
let channel = open_in_bin file in
107
let buffer = Buffer.create 20 in
110
let s = Buffer.contents buffer in
112
if trim && s <> "" && s.[String.length s - 1] = '\r' then
113
String.sub s 0 (String.length s - 1)
116
accu := s :: !accu in
119
let c = input_char channel in
126
Buffer.add_char buffer c
130
if Buffer.length buffer > 0 then
133
Array.of_list (List.rev !accu)
135
close_in_noerr channel;
142
read_aux false '\x00'
144
let write_aux sep file args =
145
let channel = open_out_bin file in
147
Array.iter (fun s -> Printf.fprintf channel "%s%c" s sep) args
149
close_out_noerr channel;
158
let parse_argv_dynamic ?current _ =
161
let parse_dynamic _ =
167
let parse_and_expand_argv_dynamic _ =