commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (JIRA)" <j...@apache.org>
Subject [jira] Commented: (CLI-137) Change of behaviour 1.0 -> 1.1
Date Thu, 29 May 2008 18:37:45 GMT

    [ https://issues.apache.org/jira/browse/CLI-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12600871#action_12600871
] 

Emmanuel Bourg commented on CLI-137:
------------------------------------

Sorry for the reformatting Russel, it was a bit compact for my eyes ;)

Steve, do you always use the option iterator to fetch the arguments from the CommandLine ?
Or do you use getOptionValues() ? I'm comparing the code in 1.0 and 1.1, if I understand well
the result should be the same in both versions with getOptionValues(). But the output of iterator()
is clearly not compatible.

Why is it important to keep the repeated options isolated instead of grouping their values
? That looks equivalent to me. Unless you start having several values per option, and the
number of values may vary. Something like :

grantaccess --user scott admin --user tom --user dean manager

This example can't be properly interpreted with CLI 1.1, it returns a list with the names
and the roles and it's impossible to know what value is a name or a role because the number
of values per option is not the same. It could be worked around by changing the format to
--user name:role, but that's the only use case I can imagine that requires the original behavior
of iterator().

> Change of behaviour 1.0 -> 1.1
> ------------------------------
>
>                 Key: CLI-137
>                 URL: https://issues.apache.org/jira/browse/CLI-137
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x
>    Affects Versions: 1.1
>         Environment: Ubuntu 7.04 Feisty Fawn (JDK 1.6.0) + Commons CLI 1.0 and 1.1
>            Reporter: Russel Winder
>            Priority: Blocker
>             Fix For: 1.2
>
>
> The code:
> {code}
> import org.apache.commons.cli.*;
> public class Trial {
>   private void execute (String[] commandLine) throws ParseException {
>     Options options = new Options();
>     options.addOption ( OptionBuilder.withLongOpt("flob").hasArg().create('F') );
>     CommandLine line = new GnuParser().parse(options, commandLine);
>     String[] results = line.getOptionValues('F');
>     if ( results != null ) { 
>       for ( String s : results ) { 
>         System.out.println( "-F " + s );
>       } 
>     }
>     results = line.getOptionValues("flob") ;
>     if ( results != null ) { 
>       for ( String s : results ) { 
>         System.out.println( "--blah " + s ); 
>       }
>     }
>     String[] theRest = line.getArgs() ;
>     for ( String s : theRest ) { 
>       System.out.print( s + " " ); 
>     }
>     System.out.println();
>   }
>   public static void main (String[] args) throws ParseException {
>     Trial trial = new Trial() ;
>     trial.execute ( new String[] { "-F1" , "-F3" , "-Fbla" , "-F 76" , "--flob" , "54"
} ) ;
>   }
> }
> {code}
> when compiled and executed under 1.0 produces:
> trial:
>      [java] -F 1
>      [java] -F 3
>      [java] -F bla
>      [java] -F  76
>      [java] -F 54
>      [java] 
> However, when compiled and executed under 1.1 produces:
> trial:
>      [java] -F 1
>      [java] --blah 1
>      [java] 3 bla  76 54 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message