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.
Check it out if you're interested! </shameless-self-promotion>
Now you've got me thinking about using dynamic/ExpandoObject for argument parsing. Hmmm ...
And whether you could have a little tool that generates a "generic" command-line exe and GUI for any assembly and hook it into the build process of your tool project.
Looks nice Sven
I'm resurrecting this thread because I've just released an update! Ookii.CommandLine 2.1 offers several improvements, including improved support for multi-value arguments, dictionary arguments, custom per-argument type converters, and various bug fixes.
For some reason this thread wasn't auto-locked, so I'm going to reuse it.
As part of a back-log of stuff that I didn't quite manage to get out the door while I was writing up my Ph.D. thesis, I am now releasing an updated version of Ookii.CommandLine. It's only a small update, which adds command line argument aliases, some updates for usage help generation, and code snippets to help with creating argument classes.
In addition, I used NuGet to create a symbols package and published it on SymbolSource, which you should apparently be able to use as a symbol server in Visual Studio without manually downloading the symbols.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.