[Mono-dev] Command Line Dispatcher

Rafael Teixeira monoman at gmail.com
Thu Jan 5 08:58:44 EST 2006


Mono.GetOptions already knows to deal with booleans and integers,
besides Strings.

Support for subcommands is planned but not currently implemented.

I would like for you to experiment with it, and send comments or even
patches to make it better.

Thanks,

On 1/4/06, Oscar Forero <oforero at novell.com> wrote:
> Hello,
>
> I am new to the list, and i will like to submit the following Utility
> to your consideration:
>
> http://forge.novell.com/modules/xfmod/project/?cmdlineparser
>
> I got tired of all the time writing those big switchs statements or
> using command line parsers that only parse the options but give you
> everything in string values and you are at the end alone with the value
> parsing.
>
> What i want it is a library that use the latest syntax extensions of C#
> and where i can wrote something like:
>
>     [SupportOperation("PrintName")]
>     public class SimpleCommand {
>
>         /// <summary>
>         ///
>         /// </summary>
>         [STAThread]
>         public static void Main(string[] Args) {
>                 // Command line parsing
>                 CommandLine cm = new CommandLine();
>                 cm.Configure(typeof(SimpleCommand));
>
>                 try {
>                         cm.Execute(Args);
>                         }
>                         catch(InvalidParameterValueException exception)
> {
>                                 cm.PrintUsage();
>                                 Console.WriteLine(exception);
>                         }
>                         catch(InvalidParameterException exception) {
>                                 cm.PrintUsage();
>                                 Console.WriteLine(exception);
>                         }
>                         catch(Novell.Util.CommandLine.InvalidOperationException
> exception) {
>                                 cm.PrintUsage();
>                                 Console.WriteLine(exception);
>                         }
>                         catch(Exception exception) {
>                                 Console.WriteLine(exception);
>                         }
>         }
>
>
>                 /// <summary>
>                 /// Get settings of iFolderWeb
>                 /// </summary>
>         [OperationParameter("n","name","Word")]
>         [OperationFlag("q","quiet")]
>         public static void OnPrintName(string name, bool quiet) {
>                         try {
>                                 if(!quiet) {
>                                         Console.Write("Your name is ");
>                                 }
>                                 Console.WriteLine(name);
>                 }
>                 catch (Exception e) {
>                                 if(!quiet) {
>                                         Console.Error.WriteLine("Error:
> {0}", e.Message);
>                                 }
>                                 Environment.Exit(-1);
>                 }
>                 }
> }
>
> If you see I did not want to dispatch the messages my self, and i want
> to get the right type for every parameter and not a generic array of
> strings or objects.
>
> Please take a look of the code present, in order to achieve this
> functionality i have to generate a Proxy class, this is done by the
> proxy compiler, it just takes an assembly as a parameter, after that the
> application is ready to run.
>
> Feedback is appreciated, positive and negative; also i will like to
> know what is missing to be useful for you guys ...
>
> regards,
>
> Oscar Forero
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>


--
Rafael "Monoman" Teixeira
---------------------------------------
As I'm currently working a lot with Java and even fixing Java VMs
(JamVM/Kaffe) and GNU Classpath code, I think I may partly borrow the
title (Javaman) from my friend Bruno Souza and become the
MonoNJavaMan. Yeah, I may currently be crazier than usual...


More information about the Mono-devel-list mailing list