Coffeehouse Thread

6 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Command line argument parser for .Net (updated)

Back to Forum: Coffeehouse
  • 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>

  • User profile image
    blowdart

    Now you've got me thinking about using dynamic/ExpandoObject for argument parsing. Hmmm ...

  • User profile image
    exoteric

    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 Smiley

  • User profile image
    Sven Groot

    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.

    It's still available on CodePlex of course, but you can now also add it your project using NuGet. There's also a sample.

  • User profile image
    Maddus Mattus

    @Sven Groot: I'll check it out!

  • User profile image
    Sven Groot

    For some reason this thread wasn't auto-locked, so I'm going to reuse it. Smiley

    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.

    Check it out if you like. Or get the NuGet package (does not include the code snippets).

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.