« Home | Firefox extension: CookiePie » | Hand-held browser » | Silverlight » | Google Finance » | Link drop V » | ShowMeDo: WASTE tutorial » | Flash video » | TWOCrowds.com flickr CAPTCHA test » | SSL + Man-in-the-Middle » | Charles Proxy » 

Sunday, July 22, 2007 

C# command line parser?

Sat down to start a little command-line app on the weekend - anyone know of a good library to parse command line arguments? Expecting something with a simple api to set up a list of arguments, specific mandatory ones, and enforce some validation (types and ranges?).

Quick Google search came up with:

Expect an update (and the finished project) soon! :)

The Mono.GetOptions library (which has been updated with a VisualStudio project file in Searcharoo) is a nice, declarative way of specifying command line arguments using Attributes.

Yes, but Mono.GetOptions will not let you specify that an argument is mandatory...will it?

NConsoler is an open source library that provides command line parser functionality based on attribute metadata attached to type.
Library is very easy to add and use in your application. NConsoler gives an ability to display help and validation messages without any line of code.

http://nconsoler.csharpus.com/

Example code:

using System;
using NConsoler;

public class Program {
public static void Main(params string[] args) {
Consolery.Run(typeof(Program), args);
}

[Action]
public static void Method(
[Required] string name,
[Optional(true)] bool flag) {
Console.WriteLine("name: {0}, flag: {1}", name, flag);
}
}

and use it:

program.exe "Maxim" /-flag

Hi,

There is a command line parser that is available on codeplex in the CommonLibrary.NET library.
( Similar to Java Commons ).


http://www.codeplex.com/commonlibrarynetIt does :
1. required / optional args
2. default values for args
3. substitutions ${today}
4. Applies arg values to an object
5. Uses attributes

Appreciate this blogg post

Post a Comment