Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

modern getopt-like option parser

Moderators: kris

Posted: 06/17/07 13:45:46

Is there some functionality to process program arguments other the C methods getopt() und getopt_long()? Would be pretty cool, as the getopt style is obsolete in D. Instead of returning from getopt, delegates for each option could be used which would make some things easier. Short and long options could also be combined. I believe, in the future this is a must-have, as getopt_long isn't ported to all platforms (okay, D isn't, too, but it should happen :) )

Author Message

Posted: 06/17/07 13:55:36

Tango already has tango.util.ArgParser which is simple and flexible. See also the tutorial.

Posted: 06/17/07 14:29:15

Oh, I missed this one :) it's at the bottom of the tutorial page *grml* :P

Posted: 06/17/07 14:50:26

Can one specify multiple names for one option? like "-h" and "--help", which is common on unix systems? Of course, one could create two anonymous delegates inside two bind() calls, or one named delegate, which two bind() calls refer to. Is there a better way?

Posted: 06/17/07 15:06:19

No, there are no easier way as of now. ArgParser was never meant to be the means to all things in this area. If you look at the comment page to the tutorial, there is a link to an implementation that is more geared toward posix compatible command line use.

Posted: 07/17/07 09:01:39

You can always use Kirk's optparse module thats modeled after pythons module. It supports both short and long options and delegates.