[Mono-devel-list] Command Line Parsing

A Rafael D Teixeira rafaelteixeirabr at hotmail.com
Tue Apr 6 20:52:06 EDT 2004


Hi Matthew,

Peter cited the answer but mistyped it a bit: We have the Mono.GetOptions 
assembly. It's fully-managed code and works well in any platform. For how to 
use it, see the MonoBASIC driver class as an example.

Mono.GetOptions is distributed with Mono and it's sources are in 
/mcs/class/Mono.GetOptions.

For your example:

>   --option=value

Basically you would code something like:

[Option("Specifies the {value} for this")]
public string option = null;

or if you would like the user to also use the " -o value" form

[Option("Specifies the {value} for this", 'o')]
public string option = null;

on a class derived from Mono.GetOptions.Options and then call 
ProcessArgs(args); in the Main method

Deriving from Options gives automatic help screen composition as a bonus.

So calling the executable with --help gives:

--option=value      Specifies the value for this

Enjoy,

Rafael "Monoman" Teixeira
Mono Hacker since 16 Jul 2001 - http://www.go-mono.org/
MonoBrasil Founding Member - Membro Fundador do MonoBrasil 
http://monobrasil.softwarelivre.org
English Blog: http://monoblog.blogspot.com/
Brazilian Portuguese Blog: http://monoblog.weblogger.terra.com.br/

>From: Met <met at uberstats.com>
>To: Mono-devel <mono-devel-list at lists.ximian.com>
>Subject: [Mono-devel-list] Command Line Parsing
>Date: Tue, 06 Apr 2004 16:02:25 -0400
>
>What tools are out there for dealing with command line arguments.  I'd
>prefer something that is portable.
>
>   --option=value
>
>~ Matthew

_________________________________________________________________
MSN Messenger: instale grátis e converse com seus amigos. 
http://messenger.msn.com.br




More information about the Mono-devel-list mailing list