Comfortable command line argument parsing
Once in a while you may want to write a command line tool which may have to accept commad line arguments. In comes a nice little bit of source code that is part of the great output of the Mono project. Documentation is available here and the source code can be taken, used directly, modified and it (obviously) compiles without any issues from .NET Framework 2.0 onwards.
An example is within the docs, in the following an example of how I intend to use it for a tool to be built that will extract information via the Team Foundation Server API:
This is a simple structure to capture the input from the arguments. Now comes the usage of the Options class:
This tells the Options API which args can be accepted. Finally comes the parsing, with input being the string array containing any arguments passed in…
Finally the showHelp method which uses the Options’ WriteOptionDescriptions method…
Based on this program, the showHelp method prints out the following:
This style of parsing and obtaining the values allows the user to use the tool without thinking much about it. It will parse…
Not bad, and readily available…