You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Berin Loritsch <bl...@apache.org> on 2002/09/12 15:17:02 UTC

[CLI] How does the Option parsing work?

I'm trying to reconcile the differences between Excalibur CLI and
Commons
CLI, so I am trying to build the compatibility testcase.  In the
process,
I tried to keep as much of the processing consistent as I could.

The assumptions of the Excalibur CLI processing is that the results are
returned in the order that they are provided on the command line.  This
is a natural assumption.  Now the key difference between the two is that
Excalibur uses an option descriptor CLOptionDescriptor that describes
the
possible options that an application can expect, and the parser returns
the list of CLOptions that were parsed.  Commons lets the application
declare a set of Options and the parser returns a CommandLine which you
can get that same set of Options with values filled in.

That subtle difference really doesn't amount to much in the great scheme
of things.  However, the *order* in which we receive the Options can be
of importance (not often, mostly for testing purposes, but
occasionally).
With Excalibur CLI I *know* that I am going to receive the options in a
list in the order that they were processed.  In Commons CLI I don't know
at all.  I think the options are added to a Set which does not preserve
any ordering information at all.

Part of the issue is that I want to ensure that a particular order of
options doesn't cause a problem (like it did on Excalibur at one point).
When I get the array of Options back from the CommandLine, I'd like to
know what order they are supposed to be in.

When I added my options to the Parser, it was in this order:

opts.addOption( ALL_OPT );
opts.addOption( TAINT_OPT );

The commandline was in this order:

String[] args = new String[] { "-T", "param", "-a" };

Excalibur CLI responds with:

CLOption: -T param
CLOption: -a

Commons CLI responds with:

Option: -a
Option: -T param

I switched the order in which I added the options, and I got the same
results.

Is there any way we can preserve the order in which the options were
processed on the command line?


"They that give up essential liberty to obtain a little temporary safety
 deserve neither liberty nor safety."
                - Benjamin Franklin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [CLI] How does the Option parsing work?

Posted by John Keyes <jb...@mac.com>.
Doh! You're correct Michael.  I'll try this later
today.

-John K

On Thu, 2002-09-12 at 14:36, Michael A. Smith wrote:
> On 12 Sep 2002, John Keyes wrote:
> > Internally, a HashMap is used, so I suppose a move to a
> > TreeMap would provide this functionality.
> 
> I would assume a tree map would be sorted based on the key, and not 
> based on the order in which it appeared on the command line.  The 
> commons collections' SequencedHashMap should work though.
> 
> regards,
> michael
> 
> > 
> > -John K
> > 
> > On Thu, 2002-09-12 at 14:17, Berin Loritsch wrote:
> > > I'm trying to reconcile the differences between Excalibur CLI and
> > > Commons
> > > CLI, so I am trying to build the compatibility testcase.  In the
> > > process,
> > > I tried to keep as much of the processing consistent as I could.
> > > 
> > > The assumptions of the Excalibur CLI processing is that the results are
> > > returned in the order that they are provided on the command line.  This
> > > is a natural assumption.  Now the key difference between the two is that
> > > Excalibur uses an option descriptor CLOptionDescriptor that describes
> > > the
> > > possible options that an application can expect, and the parser returns
> > > the list of CLOptions that were parsed.  Commons lets the application
> > > declare a set of Options and the parser returns a CommandLine which you
> > > can get that same set of Options with values filled in.
> > > 
> > > That subtle difference really doesn't amount to much in the great scheme
> > > of things.  However, the *order* in which we receive the Options can be
> > > of importance (not often, mostly for testing purposes, but
> > > occasionally).
> > > With Excalibur CLI I *know* that I am going to receive the options in a
> > > list in the order that they were processed.  In Commons CLI I don't know
> > > at all.  I think the options are added to a Set which does not preserve
> > > any ordering information at all.
> > > 
> > > Part of the issue is that I want to ensure that a particular order of
> > > options doesn't cause a problem (like it did on Excalibur at one point).
> > > When I get the array of Options back from the CommandLine, I'd like to
> > > know what order they are supposed to be in.
> > > 
> > > When I added my options to the Parser, it was in this order:
> > > 
> > > opts.addOption( ALL_OPT );
> > > opts.addOption( TAINT_OPT );
> > > 
> > > The commandline was in this order:
> > > 
> > > String[] args = new String[] { "-T", "param", "-a" };
> > > 
> > > Excalibur CLI responds with:
> > > 
> > > CLOption: -T param
> > > CLOption: -a
> > > 
> > > Commons CLI responds with:
> > > 
> > > Option: -a
> > > Option: -T param
> > > 
> > > I switched the order in which I added the options, and I got the same
> > > results.
> > > 
> > > Is there any way we can preserve the order in which the options were
> > > processed on the command line?
> > > 
> > > 
> > > "They that give up essential liberty to obtain a little temporary safety
> > >  deserve neither liberty nor safety."
> > >                 - Benjamin Franklin
> > > 
> > > 
> > > --
> > > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > > 
> > 
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [CLI] How does the Option parsing work?

Posted by "Michael A. Smith" <ma...@apache.org>.
On 12 Sep 2002, John Keyes wrote:
> Internally, a HashMap is used, so I suppose a move to a
> TreeMap would provide this functionality.

I would assume a tree map would be sorted based on the key, and not 
based on the order in which it appeared on the command line.  The 
commons collections' SequencedHashMap should work though.

regards,
michael

> 
> -John K
> 
> On Thu, 2002-09-12 at 14:17, Berin Loritsch wrote:
> > I'm trying to reconcile the differences between Excalibur CLI and
> > Commons
> > CLI, so I am trying to build the compatibility testcase.  In the
> > process,
> > I tried to keep as much of the processing consistent as I could.
> > 
> > The assumptions of the Excalibur CLI processing is that the results are
> > returned in the order that they are provided on the command line.  This
> > is a natural assumption.  Now the key difference between the two is that
> > Excalibur uses an option descriptor CLOptionDescriptor that describes
> > the
> > possible options that an application can expect, and the parser returns
> > the list of CLOptions that were parsed.  Commons lets the application
> > declare a set of Options and the parser returns a CommandLine which you
> > can get that same set of Options with values filled in.
> > 
> > That subtle difference really doesn't amount to much in the great scheme
> > of things.  However, the *order* in which we receive the Options can be
> > of importance (not often, mostly for testing purposes, but
> > occasionally).
> > With Excalibur CLI I *know* that I am going to receive the options in a
> > list in the order that they were processed.  In Commons CLI I don't know
> > at all.  I think the options are added to a Set which does not preserve
> > any ordering information at all.
> > 
> > Part of the issue is that I want to ensure that a particular order of
> > options doesn't cause a problem (like it did on Excalibur at one point).
> > When I get the array of Options back from the CommandLine, I'd like to
> > know what order they are supposed to be in.
> > 
> > When I added my options to the Parser, it was in this order:
> > 
> > opts.addOption( ALL_OPT );
> > opts.addOption( TAINT_OPT );
> > 
> > The commandline was in this order:
> > 
> > String[] args = new String[] { "-T", "param", "-a" };
> > 
> > Excalibur CLI responds with:
> > 
> > CLOption: -T param
> > CLOption: -a
> > 
> > Commons CLI responds with:
> > 
> > Option: -a
> > Option: -T param
> > 
> > I switched the order in which I added the options, and I got the same
> > results.
> > 
> > Is there any way we can preserve the order in which the options were
> > processed on the command line?
> > 
> > 
> > "They that give up essential liberty to obtain a little temporary safety
> >  deserve neither liberty nor safety."
> >                 - Benjamin Franklin
> > 
> > 
> > --
> > To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> > For additional commands, e-mail: <ma...@jakarta.apache.org>
> > 
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [CLI] How does the Option parsing work?

Posted by John Keyes <jb...@mac.com>.
Berin,

Internally, a HashMap is used, so I suppose a move to a
TreeMap would provide this functionality.

-John K

On Thu, 2002-09-12 at 14:17, Berin Loritsch wrote:
> I'm trying to reconcile the differences between Excalibur CLI and
> Commons
> CLI, so I am trying to build the compatibility testcase.  In the
> process,
> I tried to keep as much of the processing consistent as I could.
> 
> The assumptions of the Excalibur CLI processing is that the results are
> returned in the order that they are provided on the command line.  This
> is a natural assumption.  Now the key difference between the two is that
> Excalibur uses an option descriptor CLOptionDescriptor that describes
> the
> possible options that an application can expect, and the parser returns
> the list of CLOptions that were parsed.  Commons lets the application
> declare a set of Options and the parser returns a CommandLine which you
> can get that same set of Options with values filled in.
> 
> That subtle difference really doesn't amount to much in the great scheme
> of things.  However, the *order* in which we receive the Options can be
> of importance (not often, mostly for testing purposes, but
> occasionally).
> With Excalibur CLI I *know* that I am going to receive the options in a
> list in the order that they were processed.  In Commons CLI I don't know
> at all.  I think the options are added to a Set which does not preserve
> any ordering information at all.
> 
> Part of the issue is that I want to ensure that a particular order of
> options doesn't cause a problem (like it did on Excalibur at one point).
> When I get the array of Options back from the CommandLine, I'd like to
> know what order they are supposed to be in.
> 
> When I added my options to the Parser, it was in this order:
> 
> opts.addOption( ALL_OPT );
> opts.addOption( TAINT_OPT );
> 
> The commandline was in this order:
> 
> String[] args = new String[] { "-T", "param", "-a" };
> 
> Excalibur CLI responds with:
> 
> CLOption: -T param
> CLOption: -a
> 
> Commons CLI responds with:
> 
> Option: -a
> Option: -T param
> 
> I switched the order in which I added the options, and I got the same
> results.
> 
> Is there any way we can preserve the order in which the options were
> processed on the command line?
> 
> 
> "They that give up essential liberty to obtain a little temporary safety
>  deserve neither liberty nor safety."
>                 - Benjamin Franklin
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
> 



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [CLI] How does the Option parsing work?

Posted by John Keyes <jb...@mac.com>.
Berin,  do you still have this problem?  Have you had a chance
to run the test code I submitted?

Thanks,
-John K

On Thursday, Sep 12, 2002, at 13:17 Etc/GMT, Berin Loritsch wrote:

> I'm trying to reconcile the differences between Excalibur CLI and
> Commons
> CLI, so I am trying to build the compatibility testcase.  In the
> process,
> I tried to keep as much of the processing consistent as I could.
>
> The assumptions of the Excalibur CLI processing is that the results are
> returned in the order that they are provided on the command line.  This
> is a natural assumption.  Now the key difference between the two is 
> that
> Excalibur uses an option descriptor CLOptionDescriptor that describes
> the
> possible options that an application can expect, and the parser returns
> the list of CLOptions that were parsed.  Commons lets the application
> declare a set of Options and the parser returns a CommandLine which you
> can get that same set of Options with values filled in.
>
> That subtle difference really doesn't amount to much in the great 
> scheme
> of things.  However, the *order* in which we receive the Options can be
> of importance (not often, mostly for testing purposes, but
> occasionally).
> With Excalibur CLI I *know* that I am going to receive the options in a
> list in the order that they were processed.  In Commons CLI I don't 
> know
> at all.  I think the options are added to a Set which does not preserve
> any ordering information at all.
>
> Part of the issue is that I want to ensure that a particular order of
> options doesn't cause a problem (like it did on Excalibur at one 
> point).
> When I get the array of Options back from the CommandLine, I'd like to
> know what order they are supposed to be in.
>
> When I added my options to the Parser, it was in this order:
>
> opts.addOption( ALL_OPT );
> opts.addOption( TAINT_OPT );
>
> The commandline was in this order:
>
> String[] args = new String[] { "-T", "param", "-a" };
>
> Excalibur CLI responds with:
>
> CLOption: -T param
> CLOption: -a
>
> Commons CLI responds with:
>
> Option: -a
> Option: -T param
>
> I switched the order in which I added the options, and I got the same
> results.
>
> Is there any way we can preserve the order in which the options were
> processed on the command line?
>
>
> "They that give up essential liberty to obtain a little temporary 
> safety
>  deserve neither liberty nor safety."
>                 - Benjamin Franklin
>
>
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: [CLI] How does the Option parsing work?

Posted by John Keyes <jb...@mac.com>.
Berin,

I've just tried this with the current code base using the
following code:

     public static void main(String[] args) {
         try {
             Options opts = new Options();
             opts.addOption( OptionBuilder.create( 'a' ) );
             opts.addOption( OptionBuilder.hasArg().create( 'T' ) );

             String[] p = new String[] { "-T", "param", "-a" };

             PosixParser parser = new PosixParser();
             CommandLine line = parser.parse( opts, p );

             Option[] arr1 = line.getOptions();
             for( int i = 0; i < arr1.length; i++ ) {
                 System.out.println( arr1[i].getOpt() );
             }

             System.out.println( "--" );

             java.util.Iterator iter = line.iterator();
             while( iter.hasNext() ) {
                 System.out.println( iter.next() );
             }
         }
         catch( Exception exp ) {
             exp.printStackTrace();
         }

The output of this was:

T
a
--
[ option: T  :: null ]
[ option: a  :: null ]

Can you confirm this? Or send me the code you used to get
the results that you got.

Cheers,
-John K

On Thursday, Sep 12, 2002, at 13:17 Etc/GMT, Berin Loritsch wrote:

> I'm trying to reconcile the differences between Excalibur CLI and
> Commons
> CLI, so I am trying to build the compatibility testcase.  In the
> process,
> I tried to keep as much of the processing consistent as I could.
>
> The assumptions of the Excalibur CLI processing is that the results are
> returned in the order that they are provided on the command line.  This
> is a natural assumption.  Now the key difference between the two is 
> that
> Excalibur uses an option descriptor CLOptionDescriptor that describes
> the
> possible options that an application can expect, and the parser returns
> the list of CLOptions that were parsed.  Commons lets the application
> declare a set of Options and the parser returns a CommandLine which you
> can get that same set of Options with values filled in.
>
> That subtle difference really doesn't amount to much in the great 
> scheme
> of things.  However, the *order* in which we receive the Options can be
> of importance (not often, mostly for testing purposes, but
> occasionally).
> With Excalibur CLI I *know* that I am going to receive the options in a
> list in the order that they were processed.  In Commons CLI I don't 
> know
> at all.  I think the options are added to a Set which does not preserve
> any ordering information at all.
>
> Part of the issue is that I want to ensure that a particular order of
> options doesn't cause a problem (like it did on Excalibur at one 
> point).
> When I get the array of Options back from the CommandLine, I'd like to
> know what order they are supposed to be in.
>
> When I added my options to the Parser, it was in this order:
>
> opts.addOption( ALL_OPT );
> opts.addOption( TAINT_OPT );
>
> The commandline was in this order:
>
> String[] args = new String[] { "-T", "param", "-a" };
>
> Excalibur CLI responds with:
>
> CLOption: -T param
> CLOption: -a
>
> Commons CLI responds with:
>
> Option: -a
> Option: -T param
>
> I switched the order in which I added the options, and I got the same
> results.
>
> Is there any way we can preserve the order in which the options were
> processed on the command line?
>
>
> "They that give up essential liberty to obtain a little temporary 
> safety
>  deserve neither liberty nor safety."
>                 - Benjamin Franklin
>
>
> --
> To unsubscribe, e-mail:   
> <ma...@jakarta.apache.org>
> For additional commands, e-mail: 
> <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>