[Mono-dev] Command Line Dispatcher

Oscar Forero oforero at novell.com
Wed Jan 4 05:57:09 EST 2006


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



More information about the Mono-devel-list mailing list