Coffeehouse Post

Single Post Permalink

View Thread: Command line argument parser for .Net (updated)
  • User profile image
    Sven Groot

    A good while ago I posted a link here to a command line argument parser I'd written, and I just released an updated version on CodePlex. Yeah, I realize command line argument parsers are a dime a dozen, but I think it has some nice features. The basic idea is that you create a class whose properties and constructor parameters define what the arguments are. The parser will instantiate an instance of that class, set the properties, and then you can just use that instance to get at the values. Of course, you can make arguments positional or named, required or optional, give them default values, etc. You can also generate (fully customizable) usage help text consisting of command line syntax and argument descriptions.

    This version revises the API and the parsing rules substantially (to the point where it's actually not really compatible with the previous version, but whatever). The argument parsing behavior is now very close to what PowerShell uses (which I happen to like a lot).

    Another feature I added are "shell commands". The idea here is that you can have a shell utility that performs many different functions, each of which has its own set of arguments. Think for example of the windows "net" command, or the "svn" Subversion client. This library makes it really easy to define commands and their arguments, and then find, instantiate, and run the command based on the program's arguments. It's a bit of a niche functionality, but it's something I use a lot myself when writing various utilities for use in my research (in fact, it was one of the reasons I wrote the original library, even though I didn't include this bit in the released version back then).

    As an added bonus, it also contains a LineWrappingTextWriter class, which wraps any existing TextWriter and neatly wraps the output. I use it for printing stuff to the console (like the usage help for the arguments), very useful. Smiley

    Check it out if you're interested! </shameless-self-promotion>