From: Damien Doligez <Damien.Doligez@inria.fr>
To: tkb@access.mountain.net
Cc: caml-list@inria.fr
Subject: Re: Treating arguments that start with `-' as anonymous arguments
Date: Wed, 14 Jan 1998 12:14:54 +0100 [thread overview]
Message-ID: <199801141114.MAA17828@tobago.inria.fr> (raw)
I think this is a good idea, but I would make it a little bit more
versatile. Let's define a constructor Arg.Rest of (string -> void).
It causes the remaining of the command line to be sent to its
argument.
Your example becomes:
let anon s = prerr_endline ("anon arg: " ^ s);;
let speclist = [
"-a", Arg.Unit (fun () -> prerr_endline "this was -a"), "a keyword";
"--", Arg.Rest anon, "Stop interpreting keywords";
];;
Arg.parse speclist anon "usage info goes here.";;
And is is also possible to distinguish between anonymous arguments and
arguments following the "--".
I'm including my own patch at the end of this mail. Could you please
test it and tell me if it works for you ? This will be in the next
release of O'Caml unless you have some objection.
-- Damien
===================================================================
RCS file: /net/pauillac/caml/repository/csl/stdlib/arg.mli,v
retrieving revision 1.12
diff -c -r1.12 arg.mli
*** arg.mli 1997/11/05 19:44:08 1.12
--- arg.mli 1998/01/14 09:31:44
***************
*** 42,47 ****
--- 45,52 ----
| String of (string -> unit) (* Call the function with a string argument *)
| Int of (int -> unit) (* Call the function with an int argument *)
| Float of (float -> unit) (* Call the function with a float argument *)
+ | Rest of (string -> unit) (* Stop interpreting keywords and call the
+ function with each remaining argument *)
(* The concrete type describing the behavior associated
with a keyword. *)
Index: stdlib/arg.ml
===================================================================
RCS file: /net/pauillac/caml/repository/csl/stdlib/arg.ml,v
retrieving revision 1.8
diff -c -r1.8 arg.ml
*** arg.ml 1997/09/11 15:10:19 1.8
--- arg.ml 1998/01/14 09:36:53
***************
*** 18,23 ****
--- 18,25 ----
| String of (string -> unit) (* Call the function with a string argument *)
| Int of (int -> unit) (* Call the function with an int argument *)
| Float of (float -> unit) (* Call the function with a float argument *)
+ | Rest of (string -> unit) (* Stop interpreting keywords and call the
+ function with each remaining argument *)
exception Bad of string
***************
*** 91,96 ****
--- 93,103 ----
let arg = Sys.argv.(!current+1) in
f (float_of_string arg);
incr current;
+ | Rest f ->
+ while !current < l-1 do
+ f Sys.argv.(!current+1);
+ incr current;
+ done;
| _ -> stop (Missing s)
with Bad m -> stop (Message m);
end;
next reply other threads:[~1998-01-15 9:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-01-14 11:14 Damien Doligez [this message]
-- strict thread matches above, loose matches on Subject: below --
1998-01-14 1:55 T. Kurt Bond
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199801141114.MAA17828@tobago.inria.fr \
--to=damien.doligez@inria.fr \
--cc=caml-list@inria.fr \
--cc=tkb@access.mountain.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).