On Thu, 2002-10-24 at 10:17, John Keyes wrote:
> > Is this a bug?  Or am I using this incorrectly?
> > I have an option with short and long values.  Given code that is
> > essentially what is below, with a PosixParser I see results as follows:
> > 
> > A command line with just "-t" prints out the results of the catch block
> > (OK)
> > A command line with just "-target" prints out the results of the catch
> > block (OK)
> > A command line with just "-t foobar.com" prints out "processing selected
> > target: foobar.com" (OK)
> > A command line with just "-target foobar.com" prints out "processing
> > selected target: arget" (ERROR?)
> > 
> > ========================================================================
> > =======================
> >   private static final String OPTION_TARGET = "t";
> >   private static final String OPTION_TARGET_LONG = "target";
> >   // ...
> >   Option generateTarget = new Option(OPTION_TARGET, 
> >                                      OPTION_TARGET_LONG, 
> >                                      true, 
> >                                      "Generate files for the specified
> > target machine");
> >   // ...
> >   try {
> >         parsedLine = parser.parse(cmdLineOpts, args);
> >       } catch (ParseException pe) {
> >         System.out.println("Invalid command: " + pe.getMessage() +
> > "\n");
> >         HelpFormatter hf = new HelpFormatter();
> >         hf.printHelp(USAGE, cmdLineOpts);
> >         System.exit(-1);
> >       }
> > 
> >   if (parsedLine.hasOption(OPTION_TARGET)) {
> >     System.out.println("processing selected target: " +
> > parsedLine.getOptionValue(OPTION_TARGET));        
> >   }
> 
> It is a bug but it is due to well defined behaviour (so that makes
> me feel a little better about myself ;).  To support *special* 
> (well I call them special anyway) like -Dsystem.property=value we
> need to be able to examine the first character of an option.  If the
> first character is itself defined as an Option then the remainder
> of the token is used as the value, e.g. 'D' is the token, it
> is an option so 'system.property=value' is the argument value for that
> option.  This is the behaviour that we are seeing for your example.  
> 't' is the token, it is an options so 'arget' is the argument value.  
> 
> I suppose a solution to this could be to have a way to specify properties
> for parsers.  In this case 'posix.special.option == true' for turning 
> on *special* options. I'll have a look into this and let you know.

Actually, another property on Option would be cleaner and easier
to implement I would imagine.

-John K



--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>

Reply via email to