Ajout de [Arg.usage].

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1091 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Damien Doligez 1996-10-24 15:19:22 +00:00
parent c602b30b57
commit 901222ceae
2 changed files with 12 additions and 6 deletions

View File

@ -36,13 +36,13 @@ let rec assoc3 x l =
| _::t -> assoc3 x t
;;
let print_doc =
function (key, _, doc) -> eprintf " %s %s\n" key doc
let usage speclist errmsg =
eprintf "%s\n" errmsg;
List.iter (function (key, _, doc) -> eprintf " %s %s\n" key doc) speclist
;;
let parse speclist anonfun errmsg =
let stop error =
(* Print the reason for the error *)
let progname =
if Array.length Sys.argv > 0 then Sys.argv.(0) else "(?)" in
begin match error with
@ -57,9 +57,7 @@ let parse speclist anonfun errmsg =
| Message s ->
eprintf "%s: %s.\n" progname s
end;
(* Print the usage message *)
eprintf "%s\n" errmsg;
List.iter print_doc speclist;
usage speclist errmsg;
exit 2
in
let rec p = function

View File

@ -75,3 +75,11 @@ val parse : (string * spec * string) list -> (string -> unit) -> string -> unit
exception Bad of string
(* Functions in [spec] or [anonfun] can raise [Bad] with
an error message to reject invalid arguments. *)
val usage: (string * spec * string) list -> string -> unit
(*
[usage speclist errmsg]
[speclist] and [errmsg] are the same as for [parse]. [usage]
prints the same error message that [parse] prints in case of
error.
*)