www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Unable to parse command line arguments in unified way.

reply JP <joris.putcuyps skynet.be> writes:
Hello

In my experience as a c/c++ programmer I've seen a lot of quick and 
dirty, primitive command line parsing implementations. Time and time 
again because they needed something that compiles on both linux(gcc) and 
windows(msvc) and avoid using external libraries.

Even very simple console application often needs some command line parsing.

Could one, simple, implementation be part of phobos, providing portability?

Some references I found:

- Derick Eddington 30 May 2005 "optparse.d -- good enough to be 
std.optparse?"
http://www.digitalmars.com/d/archives/digitalmars/D/announce/553.html

- Daniel Keep 15 April 2006 "optparse module"
http://www.digitalmars.com/d/archives/digitalmars/D/36768.html

- doost dsource project
http://www.dsource.org/projects/doost/browser/trunk/doost/program_options

- DDL dsource project
http://www.dsource.org/projects/ddl/browser/trunk/utils/ArgParser.d

- Juanjo Álvarez Martínez
http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt

- Kirklin McDonald 1/10/2007
Optparse

Greets

Joris
Jan 12 2007
parent reply jcc7 <technocrat7 gmail.com> writes:
JP Wrote:

 Hello
 
 In my experience as a c/c++ programmer I've seen a lot of quick and 
 dirty, primitive command line parsing implementations. Time and time 
 again because they needed something that compiles on both linux(gcc) and 
 windows(msvc) and avoid using external libraries.
 
 Even very simple console application often needs some command line parsing.
 
 Could one, simple, implementation be part of phobos, providing portability?
 
 Some references I found:
 
 - Derick Eddington 30 May 2005 "optparse.d -- good enough to be 
 std.optparse?"
 http://www.digitalmars.com/d/archives/digitalmars/D/announce/553.html
 
 - Daniel Keep 15 April 2006 "optparse module"
 http://www.digitalmars.com/d/archives/digitalmars/D/36768.html
 
 - doost dsource project
 http://www.dsource.org/projects/doost/browser/trunk/doost/program_options
 
 - DDL dsource project
 http://www.dsource.org/projects/ddl/browser/trunk/utils/ArgParser.d
 
 - Juanjo Álvarez Martínez
 http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt
 
 - Kirklin McDonald 1/10/2007
 Optparse
 
 Greets
 
 Joris
I think you might have missed a couple modules (or maybe you left them off your list intentionally because there's something wrong with them such as being too out-of-date to use). See http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt for the fullest list that I know of. I agree that one of these should be added to Phobos. I don't know which one (since I haven't studied the code of any of them or even tried to use any of them yet), but it's obviously a common problem. And Phobos should be there to solve our common problems. People can still use their own version if that's what they like, but Phobos should have at least one implementation. jcc7
Jan 12 2007
parent reply JP <joris.putcuyps skynet.be> writes:
jcc7 wrote:
 JP Wrote:
 
 Hello

 In my experience as a c/c++ programmer I've seen a lot of quick and 
 dirty, primitive command line parsing implementations. Time and time 
 again because they needed something that compiles on both linux(gcc) and 
 windows(msvc) and avoid using external libraries.

 Even very simple console application often needs some command line parsing.

 Could one, simple, implementation be part of phobos, providing portability?

 Some references I found:

 - Derick Eddington 30 May 2005 "optparse.d -- good enough to be 
 std.optparse?"
 http://www.digitalmars.com/d/archives/digitalmars/D/announce/553.html

 - Daniel Keep 15 April 2006 "optparse module"
 http://www.digitalmars.com/d/archives/digitalmars/D/36768.html

 - doost dsource project
 http://www.dsource.org/projects/doost/browser/trunk/doost/program_options

 - DDL dsource project
 http://www.dsource.org/projects/ddl/browser/trunk/utils/ArgParser.d

 - Juanjo Álvarez Martínez
 http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt

 - Kirklin McDonald 1/10/2007
 Optparse

 Greets

 Joris
I think you might have missed a couple modules (or maybe you left them off your list intentionally because there's something wrong with them such as being too out-of-date to use). See http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt for the fullest list that I know of. I agree that one of these should be added to Phobos. I don't know which one (since I haven't studied the code of any of them or even tried to use any of them yet), but it's obviously a common problem. And Phobos should be there to solve our common problems. People can still use their own version if that's what they like, but Phobos should have at least one implementation. jcc7
Thanks, you're right, I might have missed some. For Linux a POSIX compliant command line argument parser is the best choice, for Windows, the options are simpler. So do we take the lesser of both or go with the standard? Joris
Jan 12 2007
next sibling parent reply Kirk McDonald <kirklin.mcdonald gmail.com> writes:
JP wrote:
 jcc7 wrote:
 
 JP Wrote:

 Hello

 In my experience as a c/c++ programmer I've seen a lot of quick and 
 dirty, primitive command line parsing implementations. Time and time 
 again because they needed something that compiles on both linux(gcc) 
 and windows(msvc) and avoid using external libraries.

 Even very simple console application often needs some command line 
 parsing.

 Could one, simple, implementation be part of phobos, providing 
 portability?

 Some references I found:

 - Derick Eddington 30 May 2005 "optparse.d -- good enough to be 
 std.optparse?"
 http://www.digitalmars.com/d/archives/digitalmars/D/announce/553.html

 - Daniel Keep 15 April 2006 "optparse module"
 http://www.digitalmars.com/d/archives/digitalmars/D/36768.html

 - doost dsource project
 http://www.dsource.org/projects/doost/browser/trunk/doost/program_options 


 - DDL dsource project
 http://www.dsource.org/projects/ddl/browser/trunk/utils/ArgParser.d

 - Juanjo Álvarez Martínez
 http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt

 - Kirklin McDonald 1/10/2007
 Optparse

 Greets

 Joris
I think you might have missed a couple modules (or maybe you left them off your list intentionally because there's something wrong with them such as being too out-of-date to use). See http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt for the fullest list that I know of. I agree that one of these should be added to Phobos. I don't know which one (since I haven't studied the code of any of them or even tried to use any of them yet), but it's obviously a common problem. And Phobos should be there to solve our common problems. People can still use their own version if that's what they like, but Phobos should have at least one implementation. jcc7
Thanks, you're right, I might have missed some. For Linux a POSIX compliant command line argument parser is the best choice, for Windows, the options are simpler. So do we take the lesser of both or go with the standard? Joris
I would like to bring up mine, again. It uses the GNU "standard" for options, and it works on both Windows and Linux (so far as I'm able to tell; I've only tested it in bash and sh, so I'm not sure if other shells do strange things with arguments). If there are any features people would like to see, I am open to adding them. I am also in the midst of writing documentation for it. My optparse has a fairly good selection of features, not all of which are laid out in the "opttest" module. The URLs for it, again, are: http://dsource.org/projects/pyd/browser/misc/optparse.d http://dsource.org/projects/pyd/browser/misc/opttest.d I'll post again when I have the documentation ready. -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Jan 12 2007
parent Kirk McDonald <kirklin.mcdonald gmail.com> writes:
Kirk McDonald wrote:
 I'll post again when I have the documentation ready.
And here we are! Documentation: http://dsource.org/projects/pyd/browser/misc/optparse.html?format=raw Source: http://dsource.org/projects/pyd/browser/misc/optparse.d Example: http://dsource.org/projects/pyd/browser/misc/opttest.d -- Kirk McDonald Pyd: Wrapping Python with D http://pyd.dsource.org
Jan 13 2007
prev sibling parent Justin C Calvarese <technocrat7 gmail.com> writes:
JP wrote:
 jcc7 wrote:
 JP Wrote:

 Hello

 In my experience as a c/c++ programmer I've seen a lot of quick and 
 dirty, primitive command line parsing implementations. Time and time 
 again because they needed something that compiles on both linux(gcc) 
 and windows(msvc) and avoid using external libraries.

 Even very simple console application often needs some command line 
 parsing.

 Could one, simple, implementation be part of phobos, providing 
 portability?

 Some references I found:

 - Derick Eddington 30 May 2005 "optparse.d -- good enough to be 
 std.optparse?"
 http://www.digitalmars.com/d/archives/digitalmars/D/announce/553.html

 - Daniel Keep 15 April 2006 "optparse module"
 http://www.digitalmars.com/d/archives/digitalmars/D/36768.html

 - doost dsource project
 http://www.dsource.org/projects/doost/browser/trunk/doost/program_options 


 - DDL dsource project
 http://www.dsource.org/projects/ddl/browser/trunk/utils/ArgParser.d

 - Juanjo Álvarez Martínez
 http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt

 - Kirklin McDonald 1/10/2007
 Optparse

 Greets

 Joris
I think you might have missed a couple modules (or maybe you left them off your list intentionally because there's something wrong with them such as being too out-of-date to use). See http://www.prowiki.org/wiki4d/wiki.cgi?Phobos/PosixGetOpt for the fullest list that I know of. I agree that one of these should be added to Phobos. I don't know which one (since I haven't studied the code of any of them or even tried to use any of them yet), but it's obviously a common problem. And Phobos should be there to solve our common problems. People can still use their own version if that's what they like, but Phobos should have at least one implementation. jcc7
Thanks, you're right, I might have missed some. For Linux a POSIX compliant command line argument parser is the best choice, for Windows, the options are simpler. So do we take the lesser of both or go with the standard? Joris
I looked at this list again and noticed that 3 of them are at least loosely based on Python's OptParse. Kirk McDonald (09 Jan 2007) http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=46527 Daniel Keep (15 Apr 2006) http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=36768 derick_eddington (30 May 2005) http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D.announce&article_id=553 I don't think Python's OptParse would be used as basic of 3 separate ports except that it must be useful. Since Kirk has done the most recent port, it'd probably be easiest to use his version as a port. It's going to work on recent version of DMD, and he probably used the coolest new features of D to implement it. But we can still look at the other versions if someone wants to recommend them (or perhaps there's a problem with Kirk's version). But I bet Kirk's version would be the easiest to use since it's been written so recently. -- jcc7
Jan 12 2007