Uploaded image for project: 'Commons CLI'
  1. Commons CLI
  2. CLI-137

Change of behaviour 1.0 -> 1.1

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • 1.1
    • 1.2
    • CLI-1.x
    • None
    • Ubuntu 7.04 Feisty Fawn (JDK 1.6.0) + Commons CLI 1.0 and 1.1

    Description

      The 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" } ) ;
        }
      }
      

      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

      Attachments

        1. repeated-options.patch
          2 kB
          Emmanuel Bourg

        Activity

          People

            Unassigned Unassigned
            russel Dr. Russel Winder
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: