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