commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Keyes <j...@mac.com>
Subject [CLI] bug in PosixParser?
Date Thu, 24 Oct 2002 09:17:27 GMT
> 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.

Just to keep track of this and to get you used to how we operate,
can you log a bug in bugzilla for this.

Thanks,
-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>


Mime
View raw message