Version française
Home     About     Download     Resources     Contact us    
Browse thread
Announcement: syntax extension for parsing command-line options
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Eric Breck <ebreck@c...>
Subject: Announcement: syntax extension for parsing command-line options
Hi folks,

Apropos of the recent discussion on the best way to handle command- 
line arguments, I'd like to announce the release of pa_arg version  
0.2.0, a syntax extension and library for parsing command-line  
options. It offers:

* a clean, simple syntax for declaring and using options
* a pure functional interface
* GNU-style or Caml-style handling of options (-ane 'arg' vs -a -n -e  
'arg')
* symbol-typed options via polymorphic variants
* generated code to produce a string representation of the chosen  
options
* sensible defaults, but powerful, extensible behavior
* and more...

The extension and supporting module, along with a detailed example and
more documentation are available at http://www.cs.cornell.edu/~ebreck/ 
pa_arg/
It's also available from GODI as godi-pa_arg (or will be as soon as  
the GODI svn archive is back up).

I'd like to thank Martin Jambon for his excellent camlp4 tutorial as  
well as detailed feedback on previous versions of this extension.

thanks!

Eric Breck

A short example (a longer example is available on the website):

main.ml contains:

open Parseopt
type option opts = {
   alpha        : help = "smoothing parameter"; float;
   beta = false : action = set; bool;
   gamma        : key = ["-x"]; [`Ecks | `Why | `Zee];
   delta        : int;
}

if the user types: ./main -alpha 0.45 -b -x why anonymous args

then then the call

parse_argv opts

returns

{alpha=Some 0.45; beta=true; gamma=Some `Ecks; delta=None}, 
["anonymous";"args"]

PS: If anyone remembers a prior posting of this to ocaml_beginners  
last year, this version is considerably improved, but somewhat  
different (for one thing,it no longer interfaces to Arg, but provides  
its own library).  Therefore, it's incompatible with that version.