Code/Tea/Etc...

Duncan Mackenzie has too much time on his hands

Command Line Switch Parser

I didn't write it (Peter Hallam did), but I was just using it and thought "wow, this is cool, it needs to be found by more people!"

If you build console apps that take multiple arguments (generate.exe /vroot:vbasic /target:c:\files\ ... etc.) then this makes it very easy. To use it, just compile the provided code into a library and reference from your own C#, VB.NET, etc. application.

From the readme;

Command Line Argument Parser
----------------------------

Author: peterhal@microsoft.com

Parsing command line arguments to a console application is a common problem.
This library handles the common task of reading arguments from a command line
and filling in the values in a type.

To use this library, define a class whose fields represent the data that your
application wants to receive from arguments on the command line. Then call
Utilities.Utility.ParseCommandLineArguments() to fill the object with the data
from the command line. Each field in the class defines a command line argument.
The type of the field is used to validate the data read from the command line.
The name of the field defines the name of the command line option.

The parser can handle fields of the following types:

- string
- int
- uint
- bool
- enum
- array of the above type

 

Published Thursday, April 10, 2003 2:17 PM by Duncanma

Comments

 

Jamie Cansdale said:

Hi Duncan,

I've commented about another way of doing this on my blog.

http://dotnetweblogs.com/nunitaddin
April 10, 2003 4:28 PM
 

Jamie Cansdale said:

I'm pleased you liked it. ;) BTW have you had a chance to try NUnitAddin? I used it extensively when knocking together that code. It's one of those applications that's easy to dogfood...

See ya, Jamie.
April 10, 2003 6:10 PM
 

Joel.... said:

Love that line..."wow, this is cool, it needs to be found by more people".... and to solve that, you stuck it on your blog...you must get a lot of traffic. Actually, I know a lot of people who regular this place of fine tea.
April 10, 2003 8:15 PM
 

Duncan Mackenzie said:

Joel, the trick is not that I get a lot of traffic... but that content on my blog is much more likely to be found by a google search than in many other places.
April 10, 2003 11:24 PM
 

Yves Reynhout said:

http://www.sellsbrothers.com's Genghis project has an alternate approach I use when writing console app's.
April 13, 2003 1:45 PM
 

TrackBack said:

Command Line Parsing with XmlSerializer : NUnitAddin
April 10, 2003 2:17 PM
 

Voltan said:

This library ("Command Line Argument Parser", by Peter Hallam) is very great. I think it can be improved. I emailed the author but did not get any answer. I'd like to improve this and publish a new version, but I need Peter's agreement.
March 24, 2004 3:24 AM
 

SweetChildOMine said:

Guns and Roses is one of the best bands ever.
June 28, 2004 2:14 PM
 

Rod said:

I disagree. Shampoo is better.
June 28, 2004 2:15 PM
 

Bill said:

Conditioner is better.
June 28, 2004 2:15 PM
Anonymous comments are disabled

This Blog

Syndication

News

This blog has moved to my own VB site

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker