Command Line Argument Parsers |
Friday, 16 July 2010 07:55 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Every now and then I'm faced with the need to have a command line interface in one of my programs. The first time I mashed up a primitive parser myself. The second time I just grabbed the first library off the net but now I finally want to get a good overview. So as a first step I'm going to collect whatever library I can find on the net. The only conditions are: it has to be build for .NET and free to use. For my own use there will be a few more criteria but that can wait for now. The List
So that's already quite a list. There were a lot more options out there in the form of code snippets on forums or contributions on programming sites but I'm deliberately leaving those out. I don't have the time to evaluate and compare every little snippet out there. Also I want to know that a particular solution was developed and improved over time based on the feedback from users and is not just the child of a one night stand with the latest C# compiler... Argument FormatNext I'm going to look at the supported argument formats. As with everything computery there are plenty of different styles on how CL arguments are supposed to be formatted. Slash vs DashOne of the main differences is what character is used to start an argument. On Windows environments programs generally use slashes to start their arguments like /help and so on. On Unix and Linux or generally with GNU software the dash variant like -v or --verbose is prevalent. Short & Long Versions / Multiple Aliases / Auto completionGNU software often allows options to be specified with short (-v) and long identifiers (--verbose). A more generic approach used by some libraries is to allow multiple aliases for the same option to be defined or to auto complete partial identifiers. Option GroupingAnother common feature isthe ability of multiple flags to be specified in compact form. Instead of writing "/a /b /c" one can achieve the same effect with "/abc" . Here is an overview of what the different projects support in that regard:
Library ReviewsBizArkBizArk seems to use the / variant exclusively, supports multiple aliases for every argument but does not allow for multiple flags to be specified in compact form. Command Line Parser LibraryThe Command Line Parser Library supports the dash variant exclusively. Both long and short versions can be used and option grouping is supported as well. CommonLibrary.NETCommonLibrary.NET seems to allow the programmer to freely define the characters to use for initiating an option and separating it from the value. On the first glance multiple aliases and compact form are not supported. c# test.netC# test.net appears to allow slash, dash and numbered parameters but is severely lacking in terms of examples. I've found a post by the developer on StackOverflow and one on his blog. The library is interesting though in it's approach since it allows completely different set of parameters for different commands. GenghisGenghis seems to support only the slash variant. Multiple aliases and grouping are not supported. Getopt .NETGetopt .NET is a port of the GNU getopt function and therefore supports the dash arguments. NDesk OptionsFormerly known as Mono.Options this library supports both slash and dash options, allows grouping and multiple aliases. TestAPITestAPI is a collection of classes for various tasks. The command line parser supports a customizable character for initiating an argument and for separating it from its value.
Ok. That's enough for now. There are a few more things I need to look at - such as how comfortable they are to work with and if they are compatible with a commercial software product. But I need a break now. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Last Updated ( Friday, 23 December 2011 14:50 ) |