[Mono-dev] Command Line Dispatcher
Oscar Forero
oforero at novell.com
Thu Jan 5 09:34:23 EST 2006
This is a complete different approach, it supports already multi valued
attributes; it is completely generic, so it is possible to use vectors
of parameters of any given type. It also have now support for
enumerations, you can get a parameter of an specific user given enum
type.
It really reduce the amount of code that somebody needs to write
because almost all the handling is done in a declarative way via
attributes, and i add support to some Types like DirectoryInfo to show
how easy is to extend the functionality to support more Types. I did it
with the intension of being extended with more type support.
I did this trying to program using the Top down approach of Extreme
Programming, first i write an application that use the library (which
still does not exist) and then write the library to support that kind of
use. And as far as i have been able to see it offer already a lot more
functionality as the libraries that exist in other languages.
I am right now working in a generic shell support, so the applications
can have an interactive mode for free.
I took a look into the Existing Classes of Mono.GetOptions and from the
amount of classes seems that my proposal is already more extensive.
Please take some time to check my library, I will of course check the
Mono.GetOptions to see if some kind of merge of ideas can be done.
I will try to write a example to compare both methods.
BTW, I did set the license to LGPL but i will be open to suggestion
about a change in order to be useful for other projects.
regards,
Oscar Forero.
>>> On Thu, Jan 5, 2006 at 2:58 pm, in message
<dd99b8c80601050558l22be14f1g3a8e8f5db62868c9 at mail.gmail.com>, Rafael
Teixeira
<monoman at gmail.com> wrote:
> 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