When building console applications that take parameters, you can use the arguments passed to Main(string[] args)
.
In the past I've simply indexed/looped that array and done a few regular expressions to extract the values. However, when the commands get more complicated, the parsing can get pretty ugly.
So I'm interested in:
- Libraries that you use
- Patterns that you use
Assume the commands always adhere to common standards such as answered here.
There is a command line argument parser at http://www.codeplex.com/commonlibrarynet
It can parse arguments using
1. attributes
2. explicit calls
3. single line of multiple arguments OR string array
It can handle things like the following:
-config:Qa -startdate:${today} -region:'New York' Settings01
It's very easy to use.
A very simple easy to use ad hoc class for command line parsing, that supports default arguments.
Look at http://github.com/mono/mono/tree/master/mcs/class/Mono.Options/
I like that one, because you can "define rules" for the arguments, needed or not,...
or if you're a Unix guy, than you might like the GNU Getopt .NET port.
I really like the Command Line Parser Library ( http://commandline.codeplex.com/ ). It has a very simple and elegant way of setting up parameters via attributes:
Powershell Commandlets.
Parsing done by powershell based on attributes specified on the commandlets, support for validations, parameter sets, pipelining, error reporting, help, and best of all returning .NET objects for use in other commandlets.
A couple links i found helpful getting started: