From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id E94CBBB91 for ; Sat, 22 Jan 2005 17:29:51 +0100 (CET) Received: from us18.unix.fas.harvard.edu (us18.unix.fas.harvard.edu [140.247.35.198]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j0MGTpoc030201 for ; Sat, 22 Jan 2005 17:29:51 +0100 Received: from [192.168.1.4] (h00080df3f267.ne.client2.attbi.com [66.30.10.194]) by us18.unix.fas.harvard.edu (8.12.11/8.12.11) with ESMTP id j0MGTkdU009398 for ; Sat, 22 Jan 2005 11:29:50 -0500 From: Martin Willensdorfer To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] 'Pass on' argument from Arg.parse to Arg.parse_argv Date: Sat, 22 Jan 2005 11:29:44 -0500 User-Agent: KMail/1.7.2 References: <20050121164812.GA16353@furbychan.cocan.org> <200501221105.27087.jon@jdh30.plus.com> In-Reply-To: <200501221105.27087.jon@jdh30.plus.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200501221129.45092.ma.wi@gmx.at> X-Miltered: at concorde with ID 41F27F7F.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; caml-list:01 argv:01 reused:01 flags:01 flags:01 replacing:01 reuse:01 command-line:01 failwith:01 failwith:01 wrote:01 wrote:01 cheers:01 caml-list:01 beginner's:01 X-Spam-Checker-Version: SpamAssassin 3.0.0 (2004-09-13) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.0 X-Spam-Level: > > Is there a way to do this? I'd like Arg.parse to ignore unknown args. I don't know if that helps you, but I had a similar situation. I also wanted to "reused" command line arguments. However, I could cramp everything into one module (config.ml). Below is an example showing you how I did it. config_1 uses its own flags and the flags defined in config_0. I am sure you can do something similar by replacing my config_0 with whatever you have in your StdArg module. Other than that, is there a way to use the things defined for Arg.parse to read values from a file when the flag '-prm_file ' is used. My list of command line arguments gets bigger and bigger and I would like to be able to use parameter files (for reproducibility and convenience) and to reuse the code written for command-line arguments. Best wishes, Martin ------------------------------------------------------ config.ml : type config_0 = { a : float; } type config_1 = { prm_config_0 : config_0 ref; dimx : int; } let default_config_0 = { a = 300.; } let default_config_1 = { prm_config_0 = ref default_config_0; dimx = 10; } (* prm for config_0 *) let set_a cf value = cf := {!cf with a = value};; (* prm for config_1 *) let set_dimx cf value = cf := {!cf with dimx = value};; let speclist_config_0 cf = [("-a", Arg.Float (set_a cf) , "commend")] let speclist_config_1 cf = [("-dimx", Arg.Int (set_dimx cf) , "x") ]@ (speclist_config_0 !cf.prm_config_0) let get_config_0_prm cf label = match label with | "a" -> Float cf.a | _ -> failwith ("get_config_0_prm: cannot find "^label^" in config") let get_config_1_prm cf label = match label with | "dimx" -> Int cf.dimx | _ -> try get_config_0_prm !(cf.prm_config_0) label with Failure message -> failwith ("get_config_0_prm: "^message) ------------------------------------------------------ usage : let read_args () = let cf = ref Config.default_config_1 in let speclist = Config.speclist_config_1 cf in let usage_msg = "whatever" in Arg.parse speclist (fun s -> ()) usage_msg; !cf;; On Saturday 22 January 2005 06:05, Jon Harrop wrote: > On Friday 21 January 2005 16:48, Richard Jones wrote: > > ... > > but this unfortunately doesn't work, because the program doesn't get > > beyond the StdArg call to Arg.parse before printing this error message > > and exiting: > > > > ./prog: unknown option `--foobar'. > > [followed by usage message] > > > > Is there a way to do this? I'd like Arg.parse to ignore unknown args. > > What about providing your StdArg module with a way to let you register new > arguments and either let you specify how they will be parsed or parse them > separately afterwards? > > Cheers, > Jon. > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs