Browse thread
'Pass on' argument from Arg.parse to Arg.parse_argv
-
Richard Jones
-
Jon Harrop
- Martin Willensdorfer
-
Jon Harrop
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-01-22 (16:29) |
From: | Martin Willensdorfer <ma.wi@g...> |
Subject: | Re: [Caml-list] 'Pass on' argument from Arg.parse to Arg.parse_argv |
> > 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 <filename>' 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