Version française
Home     About     Download     Resources     Contact us    
Browse thread
'Pass on' argument from Arg.parse to Arg.parse_argv
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: 'Pass on' argument from Arg.parse to Arg.parse_argv

I have a bunch of command-line programs which take a standard set of
arguments, so I wrote a module 'StdArg' which each program uses to
parse arguments.  That module provides an interface like this:

----------------------------------------------------------------------
val username : string
val password : string
val client : string option
(** Username, password, client passed on the command line (or defaults). *)

val update : bool
(** True if the [--update] flag was passed on the command line, instructing
  * the program to perform updates.
  *)

val verbose : bool
(** True if the [--verbose] flag was passed on the command line, instructing
  * the program to be verbose.
  *)

val args : string list
(** Remaining, unparsed arguments on the command line. *)
----------------------------------------------------------------------

Now, one of my programs requires an additional flag on the command
line.  The original idea was that this program could call:

  Arg.parse_argv args argspec [etc.]

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.

Rich.

--