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

Thomas R. Corbin corbin@samsixedd.com
Sun, 2 May 2004 13:27:40 -0400


On Thursday April 08, 2004 11:33 am, A Rafael D Teixeira wrote:
> Inline...

	This stuff is really excellent, and I am really enjoying using it.

	I'm wondering, however, if there's a way to specify a default value for an 
option, for display in the --help output?

>
> 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:
>
> <snip>
> ...
>
> [Option(-1, "Display verbose messages, use multiple times to increase
> level", 'v')]
> public bool verbosity {
>     set {
> 	HowVerbose++;
> 	Console.WriteLine("Verbosity {0}", HowVerbose);
>     }
> }
>
> ...
> </snip>
>
> then running it for debugging it shows:
>
> <output>
> 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
> </output>
>
> 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/