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

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

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

ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/CLI-137?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated CLI-137:
-------------------------------

    Description:
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



  was:
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




> 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.