caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Willensdorfer <ma.wi@gmx.at>
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	[thread overview]
Message-ID: <200501221129.45092.ma.wi@gmx.at> (raw)
In-Reply-To: <200501221105.27087.jon@jdh30.plus.com>

> > 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


      reply	other threads:[~2005-01-22 16:29 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-01-21 16:48 Richard Jones
2005-01-22 11:05 ` [Caml-list] " Jon Harrop
2005-01-22 16:29   ` Martin Willensdorfer [this message]

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=200501221129.45092.ma.wi@gmx.at \
    --to=ma.wi@gmx.at \
    --cc=caml-list@yquem.inria.fr \
    /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).