[Mono-list] Command line processing tool in C#

A Rafael D Teixeira rafael.teixeirabr@terra.com.br
Thu, 08 Apr 2004 12:33:31 -0300


On Wed, 2004-04-07 at 21:59, Jonathan Pryor wrote:
> Below...
> On Wed, 2004-04-07 at 15:15, Thomas R. Corbin wrote:
> > I've been using this tool in python:
> > 
> > http://www.python.org/doc/2.3/lib/module-optparse.html
> > 
> > And wondered if there was a similar tool in C# or for mono.
> There's a better one (in my obviously biased opinion): Mono.GetOptions.

Thanks for the compliment Jonathan...

> See the attached file for an example.  It's unique in the option-parsing
> world (AFAIK) in that it uses attributes to specify the help text,
> short, and long flags that are interpreted.

And I'm going to GETTEXTify it for descriptions WHEN I have some time...

> The one thing I can't figure out is how to specify "verbosity levels",
> where "-v -v -v" would be a valid set of command line arguments...

Well Jon your wish is my command, just updated cvs with a patch...

Now you can do something like:


[Option(-1, "Display verbose messages, use multiple times to increase
level", 'v')]
public bool verbosity {
    set {
	Console.WriteLine("Verbosity {0}", HowVerbose); 


then running it for debugging it shows:

mono myverboseprogram.exe --verbosegetoptions -v -v -v
<verbosity> set to [true]
Verbosity 1
<verbosity> set to [true]
Verbosity 2
<verbosity> set to [true]
Verbosity 3

Just yank that WriteLine and put a ceiling on it if you want (in most
uses we can just use the maximum value allowed when overflow occurs)

It will only allow it for boolean properties or boolean-accepting
methods, as a boolean field only can set with the pair of admissible
values and can't process the assignment.

>  - Jon

Enjoy, people,
Rafael "Monoman" Teixeira 
Mono Hacker since 16 Jul 2001 - http://www.go-mono.org/
Mono Brasil Founding Member - http://monobrasil.redesolbrasil.org/
English Blog: http://monoblog.blogspot.com/
Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/