You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Russel Winder <ru...@russel.org.uk> on 2007/07/31 18:28:27 UTC

Commons CLI issue

I think I must be misunderstanding something about the hasArgs.  The
program that follows produces:

    [javac] Compiling 1 source file
to /home/users/russel/Progs/OddsByLanguage/Java/CommonsCLI_Test
     [java] -D blah=Hello
     [java] -D burble=thing
     [java] -D flob=adob
     [java] -D print
     [java] 
     [java] usage: Usage statement
     [java]  -D    Definition of something.

in both 1.0 and 1.1.  I had assumed that print would not be treated a a
-D option.  Alternatively this is a bug in which case I will create a
JIRA issue -- unlikely I suspect though, much more likely to be
something stupid on my part.

Thanks.

import java.io.PrintWriter ;

import org.apache.commons.cli.CommandLine ;
import org.apache.commons.cli.OptionBuilder ;
import org.apache.commons.cli.GnuParser ;
import org.apache.commons.cli.HelpFormatter ;
import org.apache.commons.cli.Option ;
import org.apache.commons.cli.Options ;
import org.apache.commons.cli.ParseException ;
import org.apache.commons.cli.PosixParser ;

public class Trial {
  private void execute (  final String[] commandLine ) throws ParseException {
    final Options options = new Options ( ) ;
    options.addOption ( OptionBuilder.hasArgs ( ).withDescription ( "Definition of something." ).create ( 'D' ) ) ;
    final CommandLine line = ( new GnuParser ( ) ).parse ( options , commandLine ) ;
    String[] results =  line.getOptionValues ( 'D' ) ;
    if ( results != null ) { for ( String s : results ) { System.out.println ( "-D " + s ) ; } }
    String[] theRest = line.getArgs ( ) ;
    for ( String s : theRest ) { System.out.print ( s + " " ) ; }
    System.out.println ( ) ;
    final HelpFormatter formatter = new HelpFormatter ( ) ;
    final PrintWriter writer =  new PrintWriter ( System.out ) ;
    //formatter.printHelp ( writer , formatter.defaultWidth , "Usage statement" , "" , options , formatter.defaultLeftPad , formatter.defaultDescPad , "" ) ;
    formatter.printHelp ( writer , formatter.getWidth ( ) , "Usage statement" , "" , options , formatter.getLeftPadding ( ) , formatter.getDescPadding ( ) , "" ) ;
    writer.flush ( ) ;
  }
  public static void main ( final String[] args ) throws ParseException {
    final Trial trial = new Trial ( ) ;
    trial.execute ( new String[] { "-Dblah=Hello" , "-Dburble=thing" , "-Dflob=adob" , "print" } ) ;
  }
}


-- 
Russel.
====================================================
Dr Russel Winder
41 Buckmaster Road               m: +44 7770 465 077
London SW11 1EN, UK              t: +44 20 7585 2200

Re: Commons CLI issue

Posted by Russel Winder <ru...@russel.org.uk>.
On Tue, 2007-08-14 at 15:16 +0100, Henri Yandell wrote:
> On 8/13/07, Russel Winder <ru...@russel.org.uk> wrote:
> > On Mon, 2007-08-13 at 09:19 +0200, Torsten Curdt wrote:
> >
> > > Please - please don't fork. I am sure we will get your patches in. We
> > > just need someone to push for it.
> 
> +1

I'm hearing :-)

> > I believe Henri is more interested in the 1.x branch, which is why the 2.x
> > branch has not been progressed, but I am speaking from a position of
> > fairly deep ignorance.
> 
> I'm equally interested :)

Cool.

> Getting a 1.1 release out made the most sense with the time available
> - plus Brian was energetic in that direction. When I tried to use CLI2
> I didn't like the API a lot, but I was just dabbling and not trying to
> get the extra features that it supports (I assume). I seem to recall I
> found it much more verbose than CLI1 which surprised me.

I think getting 1.1 out was an excellent move and an excellent decision.

The 1.x API is well known and makes some sense.  I am only now looking
at the 2.x API and because it is different, it is odd.  I guess I need
to write a few programs to see if it works.  I definitely do not like
having to say '--xml' as parameter when querying the command line, that
strikes me a retrograde.

I am assuming that the guys who created CLI2 created the new API not for
the sake of it, but because there were serious, unrectifiable problems
with the 1.x API.  I guess the question is whether this really is the
right position.

> Now my energy for CLI is squarely available for CLI2 if there's
> interest out there.

Yes there is, unless all the problems that started the 2.x branch can
actually be fixed in 1.x.

> I can see a CLI 1.2 someday if need be, but hopefully it'll just be a
> few bugfixes and we can have people use the snapshots for that branch.

I have put one blocker issue in for 1.1, I can start generating a few
more if that helps.

What I would like to see is 1.x-SNAPSHOT in the Maven 2 snapshot
repository so that progress towards 1.2 is clear and I can use it with
bug fixes for the Groovy distribution.  (We package Commons CLI in the
Groovy distribution so I can go with snapshots :-)

> > Clearly 1.1 has many bug fixes over 1.0 and so would be preferred.
> > However the combination of the change of semantics with hasArgs and
> > incorrect processing of parameters associated with the new semantics
> > (cf. CLI-137) means that there appears to be a blocking problem in
> > processing options such as -D where there can be any number of them on a
> > command line -- there appears to be no problem with options that do not
> > have Option.UNLIMITED_VALUES set.
> 
> Any idea for how 2.0 works with this?

Not at the minute, I will have to have a play with 2.x.  I am not able
to progress properly this in the next couple of weeks, but from
mid-September onwards I can.

For me moving the whole of Commons CLI from Maven 1 to Maven 2 as the
primary build system would be good :-)

-- 
Russel.
====================================================
Dr Russel Winder
41 Buckmaster Road               m: +44 7770 465 077
London SW11 1EN, UK              t: +44 20 7585 2200

Re: Commons CLI issue

Posted by Henri Yandell <fl...@gmail.com>.
On 8/13/07, Russel Winder <ru...@russel.org.uk> wrote:
> On Mon, 2007-08-13 at 09:19 +0200, Torsten Curdt wrote:
>
> > Please - please don't fork. I am sure we will get your patches in. We
> > just need someone to push for it.

+1

> I believe Henri is more interested in the 1.x branch, which is why the 2.x
> branch has not been progressed, but I am speaking from a position of
> fairly deep ignorance.

I'm equally interested :)

Getting a 1.1 release out made the most sense with the time available
- plus Brian was energetic in that direction. When I tried to use CLI2
I didn't like the API a lot, but I was just dabbling and not trying to
get the extra features that it supports (I assume). I seem to recall I
found it much more verbose than CLI1 which surprised me.

Now my energy for CLI is squarely available for CLI2 if there's
interest out there.

I can see a CLI 1.2 someday if need be, but hopefully it'll just be a
few bugfixes and we can have people use the snapshots for that branch.

> Clearly 1.1 has many bug fixes over 1.0 and so would be preferred.
> However the combination of the change of semantics with hasArgs and
> incorrect processing of parameters associated with the new semantics
> (cf. CLI-137) means that there appears to be a blocking problem in
> processing options such as -D where there can be any number of them on a
> command line -- there appears to be no problem with options that do not
> have Option.UNLIMITED_VALUES set.

Any idea for how 2.0 works with this?

Hen

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


Re: Commons CLI issue

Posted by Torsten Curdt <tc...@apache.org>.
>> Please - please don't fork. I am sure we will get your patches in. We
>> just need someone to push for it.
>
> That's what I like to hear :-)

<snip type="yepp yepp yepp"/>

:)

> If Commons CLI is to be reenergized (over and above what Henri did to
> get 1.1 out) then this is a good thing.

Well, as said: come and join us on the dev list.

cheers
--
Torsten

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


Re: Commons CLI issue

Posted by Russel Winder <ru...@russel.org.uk>.
On Mon, 2007-08-13 at 09:19 +0200, Torsten Curdt wrote:

> Please - please don't fork. I am sure we will get your patches in. We  
> just need someone to push for it.

That's what I like to hear :-)

The single biggest decision that needs to be made is whether the current
2.x branch is the future or whether it should be deleted and the 1.x
branch continue as the released CLI.  If 2.x is the future then there
needs to be a release and a version put into the Maven repository.  I
believe Henri is more interested in the 1.x branch, which is why the 2.x
branch has not been progressed, but I am speaking from a position of
fairly deep ignorance.

Clearly 1.1 has many bug fixes over 1.0 and so would be preferred.
However the combination of the change of semantics with hasArgs and
incorrect processing of parameters associated with the new semantics
(cf. CLI-137) means that there appears to be a blocking problem in
processing options such as -D where there can be any number of them on a
command line -- there appears to be no problem with options that do not
have Option.UNLIMITED_VALUES set.

As I say we can use the 1.0 semantics and hack round things, but we
cannot use 1.1 because of the incorrect processing :-(

The other thing I need is the -- option that terminates option
processing.  This is in 2.x but not in 1.x I believe.

If Commons CLI is to be reenergized (over and above what Henri did to
get 1.1 out) then this is a good thing.

-- 
Russel.
====================================================
Dr Russel Winder
41 Buckmaster Road               m: +44 7770 465 077
London SW11 1EN, UK              t: +44 20 7585 2200

Re: Commons CLI issue

Posted by Torsten Curdt <tc...@apache.org>.
On 13.08.2007, at 07:37, Russel Winder wrote:

> On Sat, 2007-08-11 at 20:32 +0200, Torsten Curdt wrote:
>> I'd suggest to ask that on the dev list ...a few cli issues have been
>> brought up there lately
>
> OK, thanks for letting me know.  It is difficult to decide if CLI is a
> live project or a dead project - despite my recent direct email  
> exchange
> with Henri.  We use it in Groovy, but there is a growing feeling in  
> the
> team that we should fork the CLI code so we can get the fixes we  
> need in
> place ready for the next Groovy release.  The decision is really  
> whether
> to fork the unreleased 2.x or the the released 1.x branch.

Please - please don't fork. I am sure we will get your patches in. We  
just need someone to push for it.

cheers
--
Torsten

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


Re: Commons CLI issue

Posted by Russel Winder <ru...@russel.org.uk>.
On Sat, 2007-08-11 at 20:32 +0200, Torsten Curdt wrote:
> I'd suggest to ask that on the dev list ...a few cli issues have been  
> brought up there lately

OK, thanks for letting me know.  It is difficult to decide if CLI is a
live project or a dead project - despite my recent direct email exchange
with Henri.  We use it in Groovy, but there is a growing feeling in the
team that we should fork the CLI code so we can get the fixes we need in
place ready for the next Groovy release.  The decision is really whether
to fork the unreleased 2.x or the the released 1.x branch.

-- 
Russel.
====================================================
Dr Russel Winder
41 Buckmaster Road               m: +44 7770 465 077
London SW11 1EN, UK              t: +44 20 7585 2200

Re: Commons CLI issue

Posted by Torsten Curdt <tc...@apache.org>.
I'd suggest to ask that on the dev list ...a few cli issues have been  
brought up there lately

cheers
--
Torsten

On 31.07.2007, at 18:28, Russel Winder wrote:

> I think I must be misunderstanding something about the hasArgs.  The
> program that follows produces:
>
>     [javac] Compiling 1 source file
> to /home/users/russel/Progs/OddsByLanguage/Java/CommonsCLI_Test
>      [java] -D blah=Hello
>      [java] -D burble=thing
>      [java] -D flob=adob
>      [java] -D print
>      [java]
>      [java] usage: Usage statement
>      [java]  -D    Definition of something.
>
> in both 1.0 and 1.1.  I had assumed that print would not be treated  
> a a
> -D option.  Alternatively this is a bug in which case I will create a
> JIRA issue -- unlikely I suspect though, much more likely to be
> something stupid on my part.
>
> Thanks.
>
> import java.io.PrintWriter ;
>
> import org.apache.commons.cli.CommandLine ;
> import org.apache.commons.cli.OptionBuilder ;
> import org.apache.commons.cli.GnuParser ;
> import org.apache.commons.cli.HelpFormatter ;
> import org.apache.commons.cli.Option ;
> import org.apache.commons.cli.Options ;
> import org.apache.commons.cli.ParseException ;
> import org.apache.commons.cli.PosixParser ;
>
> public class Trial {
>   private void execute (  final String[] commandLine ) throws  
> ParseException {
>     final Options options = new Options ( ) ;
>     options.addOption ( OptionBuilder.hasArgs ( ).withDescription  
> ( "Definition of something." ).create ( 'D' ) ) ;
>     final CommandLine line = ( new GnuParser ( ) ).parse  
> ( options , commandLine ) ;
>     String[] results =  line.getOptionValues ( 'D' ) ;
>     if ( results != null ) { for ( String s : results )  
> { System.out.println ( "-D " + s ) ; } }
>     String[] theRest = line.getArgs ( ) ;
>     for ( String s : theRest ) { System.out.print ( s + " " ) ; }
>     System.out.println ( ) ;
>     final HelpFormatter formatter = new HelpFormatter ( ) ;
>     final PrintWriter writer =  new PrintWriter ( System.out ) ;
>     //formatter.printHelp ( writer , formatter.defaultWidth ,  
> "Usage statement" , "" , options , formatter.defaultLeftPad ,  
> formatter.defaultDescPad , "" ) ;
>     formatter.printHelp ( writer , formatter.getWidth ( ) , "Usage  
> statement" , "" , options , formatter.getLeftPadding ( ) ,  
> formatter.getDescPadding ( ) , "" ) ;
>     writer.flush ( ) ;
>   }
>   public static void main ( final String[] args ) throws  
> ParseException {
>     final Trial trial = new Trial ( ) ;
>     trial.execute ( new String[] { "-Dblah=Hello" , "- 
> Dburble=thing" , "-Dflob=adob" , "print" } ) ;
>   }
> }
>
>
> -- 
> Russel.
> ====================================================
> Dr Russel Winder
> 41 Buckmaster Road               m: +44 7770 465 077
> London SW11 1EN, UK              t: +44 20 7585 2200


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