You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Russel Winder (JIRA)" <ji...@apache.org> on 2007/07/22 09:26:06 UTC

[jira] Created: (CLI-137) Change of behaviour 1.0 -> 1.1

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
         Environment: Ubuntu 7.04 Feisty Fawn (JDK 1.6.0) + Commons CLI 1.0 and 1.1
            Reporter: Russel Winder
            Priority: Blocker


The code:
{code}
import org.apache.commons.cli.CommandLine ;
import org.apache.commons.cli.OptionBuilder ;
import org.apache.commons.cli.GnuParser ;
import org.apache.commons.cli.Option ;
import org.apache.commons.cli.Options ;
import org.apache.commons.cli.ParseException ;

public class Trial {
  private void execute (  final String[] commandLine ) throws ParseException {
    final Options options = new Options ( ) ;
    options.addOption ( OptionBuilder.withLongOpt ( "flob" ).hasArg ( ).create ( 'F' ) ) ;
    final 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 ( final String[] args ) throws ParseException {
    final 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.


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


[jira] Commented: (CLI-137) Change of behaviour 1.0 -> 1.1

Posted by "Brian Egge (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12514577 ] 

Brian Egge commented on CLI-137:
--------------------------------

In 1.1, the hasArg() set the number of expected values to '1'.  Apparently, in 1.0 it defaulted to unlimited.   You can get the previous behavior by changing the code like this:

Option option = OptionBuilder.withLongOpt("flob").hasArgs().create('F');

The output will then look like:
-F 1
-F 3
-F bla
-F  76
-F 54
--blah 1
--blah 3
--blah bla
--blah  76
--blah 54

In 1.1, you can call getOptionValues by either the short name or the long name.  Since they are the same option, they return the same values.  

hasArg expects a single value, while hasArgs allows unlimited values.  I think this behavior, although different, is what the original API has intended.  

> 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
>         Environment: Ubuntu 7.04 Feisty Fawn (JDK 1.6.0) + Commons CLI 1.0 and 1.1
>            Reporter: Russel Winder
>            Priority: Blocker
>
> The code:
> {code}
> import org.apache.commons.cli.CommandLine ;
> import org.apache.commons.cli.OptionBuilder ;
> import org.apache.commons.cli.GnuParser ;
> import org.apache.commons.cli.Option ;
> import org.apache.commons.cli.Options ;
> import org.apache.commons.cli.ParseException ;
> public class Trial {
>   private void execute (  final String[] commandLine ) throws ParseException {
>     final Options options = new Options ( ) ;
>     options.addOption ( OptionBuilder.withLongOpt ( "flob" ).hasArg ( ).create ( 'F' ) ) ;
>     final 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 ( final String[] args ) throws ParseException {
>     final 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.


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


[jira] Commented: (CLI-137) Change of behaviour 1.0 -> 1.1

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12515729 ] 

Henri Yandell commented on CLI-137:
-----------------------------------

Is this a viable workaround Russel?

> 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
>         Environment: Ubuntu 7.04 Feisty Fawn (JDK 1.6.0) + Commons CLI 1.0 and 1.1
>            Reporter: Russel Winder
>            Priority: Blocker
>
> The code:
> {code}
> import org.apache.commons.cli.CommandLine ;
> import org.apache.commons.cli.OptionBuilder ;
> import org.apache.commons.cli.GnuParser ;
> import org.apache.commons.cli.Option ;
> import org.apache.commons.cli.Options ;
> import org.apache.commons.cli.ParseException ;
> public class Trial {
>   private void execute (  final String[] commandLine ) throws ParseException {
>     final Options options = new Options ( ) ;
>     options.addOption ( OptionBuilder.withLongOpt ( "flob" ).hasArg ( ).create ( 'F' ) ) ;
>     final 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 ( final String[] args ) throws ParseException {
>     final 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.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


[jira] Commented: (CLI-137) Change of behaviour 1.0 -> 1.1

Posted by "Russel Winder (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-137?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12515737 ] 

Russel Winder commented on CLI-137:
-----------------------------------

Yes and no.  There appear to be problems but it is not clear whether these are problems in the Groovy use of Commons CLI, or whether there are bugs in Commons CLI.  I am hesitant to report bugs in 1.0 since most are probably all removed in 1.1.  However, 1.1 is not working as it should with Groovy.  A bit of a chicken and egg situation.


> 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
>         Environment: Ubuntu 7.04 Feisty Fawn (JDK 1.6.0) + Commons CLI 1.0 and 1.1
>            Reporter: Russel Winder
>            Priority: Blocker
>
> The code:
> {code}
> import org.apache.commons.cli.CommandLine ;
> import org.apache.commons.cli.OptionBuilder ;
> import org.apache.commons.cli.GnuParser ;
> import org.apache.commons.cli.Option ;
> import org.apache.commons.cli.Options ;
> import org.apache.commons.cli.ParseException ;
> public class Trial {
>   private void execute (  final String[] commandLine ) throws ParseException {
>     final Options options = new Options ( ) ;
>     options.addOption ( OptionBuilder.withLongOpt ( "flob" ).hasArg ( ).create ( 'F' ) ) ;
>     final 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 ( final String[] args ) throws ParseException {
>     final 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.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org