views:

1080

answers:

7

There is this post for .Net, but it is not really informative. Any other suggestions? This must be a duplicate, though my first cursory search only turned up the one I already mentioned.


Duplicate of:

+6  A: 

Each language would most likely require different command line parsing code.

Brian R. Bondy
I use the CodeProject code for several of my utilities. It works great!
hectorsosajr
+2  A: 

Bob Martin (one of the most well-known and respected software guys out there) uses a command-line parser as a tutorial on writing clean code. This is one of his most lauded demonstrations - he has given it countless times in many countries. The end-product is nice, it's very easy and quick to follow along, and you learn a lot about clean coding practices along the way.

The example code is in Java, but it's intended for developers using any language and it's doled out in a few lines of code at a time, with heavy explanation.

Command-line parser Tutorial (warning, PDF)

Rex M
+6  A: 

For C, there is the classic getopt.

David Norman
A: 

I will have to second Brian's recommendation of boost.program_options. It is very good; I have used it before and is pretty easy and very customizable.

rlbond
+1  A: 

For C#, there's also this post.

And, I did a short series on command line option parsing for my InformIT column. It's not the end-all, but it's simple and I find it quite useful.

Jim Mischel
A: 

For .NET: Nini.

Not only does it do commandline option parsing, but you can load your commandline options from any standard configuration file (you could set commandline defaults in an INI or XML file, then have the switches override those defaults).

Setting up and retrieving parameters is fairly straight forward and gives you the options to define default values to return if nonspecified. If your doing anything remotely complex, the ability to outsource to a config file for those defaults can be invaluable too.

Adam Frisby