Version française
Home     About     Download     Resources     Contact us    
Browse thread
Use Arg module to read keyword followed by unspecified number of arguments
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] Use Arg module to read keyword followed by unspecified number of arguments
On Tue, May 23, 2006 at 12:17:18PM -0500, mulhern wrote:
> Hi!
> 
> I expect to be reading something like this:
> 
> -pred-files <arg1> <arg2> ... <argn> -key2 <arg> -extra-files <arg1>
> <arg2> ... <argn> -key4
> 
> There may be 0 or more <args> specified after -pred-files and after
> -extra-files. I need to treat the args differently depending on what
> keyword they are associated with.

Do you need a keyword for these pred-files arg's?

Why don't you use un-named (anonyme) args?

It looks like a filelist.

The last anonymous function ( "(fun name -> if Sy.file_exists name"(...) )
will be called for all args that are givewn, without a switch that
specifies which kind of arg will follow.


Example:

let parse () = (*print_endline "OK, starting the parse!";*)
    Arg.parse [
         ("-dp", Arg.String (fun x -> dirnameopt := Prefix x), " <dirpref> directory name-prefix");
         ("-fd", Arg.String (fun x -> dirnameopt := Fixed x), "<fixdir> fixed directory name");
         ("-inv", Arg.Unit (fun () -> filter_selection := Inverted ), " invert the template filter ... <template>" );
         ("-ad", Arg.Unit (fun () -> fk_sel := Allow_dirs ), " allow dirs to be moved ...!" );
         ("-v", Arg.Unit (fun () -> Printf.printf "%s\n" version;exit 0), " version of the program" )
              ] 
         ( fun name -> if Sys.file_exists name then Hashtbl.replace filenames name "" ) 
         "Use the program with following options:"




Hope, this helps.



Ciao,
   Oliver