1Stdlib.Arg(3)                    OCaml library                   Stdlib.Arg(3)
2
3
4

NAME

6       Stdlib.Arg - no description
7

Module

9       Module   Stdlib.Arg
10

Documentation

12       Module Arg
13        : (module Stdlib__arg)
14
15
16
17
18
19
20
21       type spec =
22        | Unit of (unit -> unit)
23         (* Call the function with unit argument
24        *)
25        | Bool of (bool -> unit)
26         (* Call the function with a bool argument
27        *)
28        | Set of bool ref
29         (* Set the reference to true
30        *)
31        | Clear of bool ref
32         (* Set the reference to false
33        *)
34        | String of (string -> unit)
35         (* Call the function with a string argument
36        *)
37        | Set_string of string ref
38         (* Set the reference to the string argument
39        *)
40        | Int of (int -> unit)
41         (* Call the function with an int argument
42        *)
43        | Set_int of int ref
44         (* Set the reference to the int argument
45        *)
46        | Float of (float -> unit)
47         (* Call the function with a float argument
48        *)
49        | Set_float of float ref
50         (* Set the reference to the float argument
51        *)
52        | Tuple of spec list
53         (* Take several arguments according to the spec list
54        *)
55        | Symbol of string list * (string -> unit)
56         (* Take one of the symbols as argument and call the function with the
57       symbol
58        *)
59        | Rest of (string -> unit)
60         (* Stop interpreting keywords and call the function with each remain‐
61       ing argument
62        *)
63        | Expand of (string -> string array)
64         (*  If  the  remaining  arguments to process are of the form ["-foo";
65       "arg"] @ rest where "foo" is registered as Expand f ,  then  the  argu‐
66       ments  f  "arg"  @  rest  are  processed. Only allowed in parse_and_ex‐
67       pand_argv_dynamic .
68        *)
69
70
71       The concrete type describing the behavior associated with a keyword.
72
73
74       type key = string
75
76
77
78
79       type doc = string
80
81
82
83
84       type usage_msg = string
85
86
87
88
89       type anon_fun = string -> unit
90
91
92
93
94
95       val parse : (key * spec * doc) list -> anon_fun -> usage_msg -> unit
96
97
98       Arg.parse  speclist  anon_fun  usage_msg  parses  the   command   line.
99       speclist  is  a  list  of triples (key, spec, doc) .  key is the option
100       keyword, it must start with a '-' character.   spec  gives  the  option
101       type  and the function to call when this option is found on the command
102       line.  doc is a one-line  description  of  this  option.   anon_fun  is
103       called  on anonymous arguments.  The functions in spec and anon_fun are
104       called in the same order as their arguments appear on the command line.
105
106       If an error occurs, Arg.parse exits  the  program,  after  printing  to
107       standard error an error message as follows:
108
109       -   The  reason for the error: unknown option, invalid or missing argu‐
110       ment, etc.
111
112       - usage_msg
113
114
115       -  The list of options, each followed by the corresponding doc  string.
116       Beware:  options  that have an empty doc string will not be included in
117       the list.
118
119       For the user to be able to specify anonymous arguments starting with  a
120       - , include for example ("-", String anon_fun, doc) in speclist .
121
122       By default, parse recognizes two unit options, -help and --help , which
123       will print to standard output usage_msg and the list  of  options,  and
124       exit  the  program.  You can override this behaviour by specifying your
125       own -help and --help options in speclist .
126
127
128
129       val parse_dynamic : (key * spec * doc) list  ref  ->  anon_fun  ->  us‐
130       age_msg -> unit
131
132       Same  as  Arg.parse  , except that the speclist argument is a reference
133       and may be updated during the parsing. A typical use for  this  feature
134       is to parse command lines of the form:
135
136       -     command  subcommand  options where the list of options depends on
137       the value of the subcommand argument.
138
139
140
141       Since 4.01.0
142
143
144
145       val parse_argv : ?current:int ref -> string array -> (key * spec * doc)
146       list -> anon_fun -> usage_msg -> unit
147
148
149       Arg.parse_argv ~current args speclist anon_fun usage_msg parses the ar‐
150       ray args as if it were the command line.  It uses and updates the value
151       of  ~current (if given), or Arg.current .  You must set it before call‐
152       ing parse_argv .  The initial value of current is the index of the pro‐
153       gram   name   (argument   0)   in  the  array.   If  an  error  occurs,
154       Arg.parse_argv raises Arg.Bad with the error message as  argument.   If
155       option  -help  or  --help is given, Arg.parse_argv raises Arg.Help with
156       the help message as argument.
157
158
159
160       val parse_argv_dynamic : ?current:int ref -> string  array  ->  (key  *
161       spec * doc) list ref -> anon_fun -> string -> unit
162
163       Same  as Arg.parse_argv , except that the speclist argument is a refer‐
164       ence and may be updated during the parsing.  See Arg.parse_dynamic .
165
166
167       Since 4.01.0
168
169
170
171       val parse_and_expand_argv_dynamic : int ref -> string array ref -> (key
172       * spec * doc) list ref -> anon_fun -> string -> unit
173
174       Same  as  Arg.parse_argv_dynamic  ,  except that the argv argument is a
175       reference and may be updated during the parsing  of  Expand  arguments.
176       See Arg.parse_argv_dynamic .
177
178
179       Since 4.05.0
180
181
182
183       val  parse_expand : (key * spec * doc) list -> anon_fun -> usage_msg ->
184       unit
185
186       Same as Arg.parse , except that the Expand arguments  are  allowed  and
187       the Arg.current reference is not updated.
188
189
190       Since 4.05.0
191
192
193
194       exception Help of string
195
196
197       Raised by Arg.parse_argv when the user asks for help.
198
199
200
201       exception Bad of string
202
203
204       Functions  in  spec or anon_fun can raise Arg.Bad with an error message
205       to reject invalid arguments.  Arg.Bad is also raised by  Arg.parse_argv
206       in case of an error.
207
208
209
210       val usage : (key * spec * doc) list -> usage_msg -> unit
211
212
213       Arg.usage  speclist usage_msg prints to standard error an error message
214       that includes the list of valid options.  This is the same message that
215       Arg.parse prints in case of error.  speclist and usage_msg are the same
216       as for Arg.parse .
217
218
219
220       val usage_string : (key * spec * doc) list -> usage_msg -> string
221
222       Returns the message that would have been printed by Arg.usage , if pro‐
223       vided with the same parameters.
224
225
226
227       val align : ?limit:int -> (key * spec * doc) list -> (key * spec * doc)
228       list
229
230       Align the documentation strings by inserting spaces at the first align‐
231       ment  separator  (tab or, if tab is not found, space), according to the
232       length of the keyword.  Use a alignment separator as the first  charac‐
233       ter  in  a  doc  string if you want to align the whole string.  The doc
234       strings corresponding to Symbol arguments are aligned on the next line.
235
236
237
238       val current : int ref
239
240       Position (in Sys.argv ) of  the  argument  being  processed.   You  can
241       change  this  value,  e.g.  to  force Arg.parse to skip some arguments.
242       Arg.parse uses the initial value of Arg.current as the index  of  argu‐
243       ment 0 (the program name) and starts parsing arguments at the next ele‐
244       ment.
245
246
247
248       val read_arg : string -> string array
249
250
251       Arg.read_arg file reads newline-terminated command line arguments  from
252       file file .
253
254
255       Since 4.05.0
256
257
258
259       val read_arg0 : string -> string array
260
261       Identical to Arg.read_arg but assumes null character terminated command
262       line arguments.
263
264
265       Since 4.05.0
266
267
268
269       val write_arg : string -> string array -> unit
270
271
272       Arg.write_arg file args writes the  arguments  args  newline-terminated
273       into  the  file  file  . If the any of the arguments in args contains a
274       newline, use Arg.write_arg0 instead.
275
276
277       Since 4.05.0
278
279
280
281       val write_arg0 : string -> string array -> unit
282
283       Identical to Arg.write_arg but uses the null character  for  terminator
284       instead of newline.
285
286
287       Since 4.05.0
288
289
290
291
292
293OCamldoc                          2021-01-26                     Stdlib.Arg(3)
Impressum