caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Goswin von Brederlow <goswin-v-b@web.de>
To: caml-list@yquem.inria.fr
Subject: [Caml-list] Command line argument parsing
Date: Mon, 27 Dec 2010 18:32:34 +0100	[thread overview]
Message-ID: <874o9zw28d.fsf@frosties.localnet> (raw)

Hi,

I'm looking for a better (as more suitable to my wishes :) module to do
command line argument parsing.

So far I've looked at Arg and Getopt. Args has a nice automatic help
text while Getopt supports short and long options. I want both. :)
Further both only allow parsing all option in one go.


So what am I looking for?
=========================

Consider the following usage:

foo [-p|--port <num>] [-h|--help] [-v|--verbose] [[-f|--file] <name>] [...]

port defaults to 1234


Then I want to write something like:

let port_arg = Int [Short 'p'; Long "port"; Once; Default 1234]
let help_arg = Unit [Short 'h'; Long "help"; Exit; ]
let verbose_arg  Count [Short 'v'; Long "verbose" ]
let file_arg = Call_String ([Short 'f'; Long "file" ], (fun s -> process s))

let port = extract port_arg
let verbose = extract verbose_arg
let () = extract help_arg
let () = parse [file_arg] (fun s -> process s) "Help text header"

I don't want to have to use a ref or mutable to define a port and then
overwrite it when parsing the arguments.

Anyone know something in that direction?

MfG
        Goswin

                 reply	other threads:[~2010-12-27 17:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=874o9zw28d.fsf@frosties.localnet \
    --to=goswin-v-b@web.de \
    --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).