commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rob Oxspring <roxspr...@imapmail.org>
Subject [CLI] Application utility class (was Re: [CLI] PatternOptionBuilder)
Date Sat, 27 Mar 2004 11:10:36 GMT
Moving to the list for wider comment. (will reply separately)

-------- Original Message --------
Subject: Re: [CLI] PatternOptionBuilder
Date: Fri, 26 Mar 2004 17:39:21 -0500 (EST)
From: Michael Heuer <heuermh@acm.org>
To: Rob Oxspring <roxspring@imapmail.org>


On Fri, 26 Mar 2004, Rob Oxspring wrote:

> I'm pretty sure this is doable in cli2, is there any particular part of
> it that's causing you problems?

I guess I'm looking for something like the attached file

   Application.java

(although to be honest I don't really like the class name)

I'm a bit confused on the createOptions() method -- do I have this right
by returning a Group containing all the Options?  Perhaps you could show
me or point me to an example of what this method's implementation might
look like.

If I wanted the Application class to add "standard" options like --help
and --verbose should I just add those to the Group that is returned?

In my 1.0 version the abstract class held an instance of Options and the
abstract method was

   protected abstract addOption(Option);

Thank you for your help.

    michael



-------- Original Message --------
Subject: Re: [CLI] PatternOptionBuilder
Date: Fri, 26 Mar 2004 17:53:11 -0500 (EST)
From: Michael Heuer <heuermh@acm.org>
To: Rob Oxspring <roxspring@imapmail.org>


I guess I'd also like it if

   parser.parseAndHelp(String[])

did something better than return null if an OptionException is thrown.  Or
maybe I should call parser.parse(String[]) and deal with the exceptions
myself?

This illustrates the problem:


$ java -classpath "commons-cli-2.0.jar;." MyTask --not-a-valid-option
Unexpected --not-a-valid-option while processing
Usage:
  []

hello world.


given

MyTask.java

import org.apache.commons.cli2.Group;
import org.apache.commons.cli2.Application;
import org.apache.commons.cli2.builders.GroupBuilder;

public class MyTask
     extends Application
{
     public MyTask(final String[] args)
     {
         super(args);
     }

     protected Group createOptions()
     {
         return new GroupBuilder().create();
     }
     public void run()
     {
         System.out.println("hello world.");
     }

     public static void main(final String args[])
     {
         MyTask mt = new MyTask(args);
         mt.run();
     }
}



Mime
View raw message