Common CLi Usage

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Common CLi Usage

John O'Sullivan-2
Hi

I new to using the apache commons cli I am struggling to get this
correct and would really appreciate any help.

I need to add an option to my command line (-p) with a variable number
of options like the following..

Note there are other options -a, -f, -d but I am not interested in them
for now
e.g

myApp -p [<name> | <Time> | <Boolean>] -a XXX -d xxx -f XXX

where time is of the format 'YYYY-MM-DD HH:MM:SS'
Note
1. There is a space between the "YYYY-MM-DD"  and the "HH:MM:SS"(does
this mean the CLI Parser will see 2 parameters )
2. The <time> and <boolean> parameters are optional.
3. The <name> parameter is mandatory when using the -p option

I am using the Commons Cli API..
I am trying to define the option as follows but this obviously isnt
correct

final Option persistDataOption =
OptionBuilder.withArgName("persist").hasOptionalArgs(3)
hasArg().withDescription("Persist Data with Scheduling")
.create(CLIOption.PERSIST_DATA.getOptionString());
where
CLIOption.PERSIST_DATA.getOptionString()) will return the "-p" option

Can someone please show me how to define this command line option
correctly please

Thanks in advance

John

       



> ericssonl
> John O'Sullivan
> Ericsson Software Campus
> Athlone.
> Co. Westmeath
> Ireland
> *ECN 21389
> *External +353 90 6431389
> [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Common CLi Usage

Russel Winder-2
On Thu, 2008-05-29 at 12:58 +0200, John O'Sullivan wrote:

> myApp -p [<name> | <Time> | <Boolean>] -a XXX -d xxx -f XXX
>
> where time is of the format 'YYYY-MM-DD HH:MM:SS'
> Note
> 1. There is a space between the "YYYY-MM-DD"  and the "HH:MM:SS"(does
> this mean the CLI Parser will see 2 parameters )
> 2. The <time> and <boolean> parameters are optional.
> 3. The <name> parameter is mandatory when using the -p option
>
> I am using the Commons Cli API..
> I am trying to define the option as follows but this obviously isnt
> correct
>
> final Option persistDataOption =
> OptionBuilder.withArgName("persist").hasOptionalArgs(3)
> hasArg().withDescription("Persist Data with Scheduling")
> .create(CLIOption.PERSIST_DATA.getOptionString());
> where
> CLIOption.PERSIST_DATA.getOptionString()) will return the "-p" option
>
> Can someone please show me how to define this command line option
> correctly please
I don't have an immediate answer for you I'm afraid.  The reason for
replying is to note that this looks almost, but not quite exactly, like
an ISO 8601 date -- the differences are going to be very irritating I
suspect.  The though struck me that ISO 8601 date should be a known
construct to any CLI system.  Of course, Java's current date system is
effectively rubbish, and JodaTime isn't yet standard.

I suspect the only way forward for the moment is to quote the date
string as a parameter or use the full no space ISO 8601 format (i.e.
replace space with T), and then ship the string to a JodaTime function
for parsing.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Common CLi Usage

John O'Sullivan-2
Hi russel,
Thanks for your reply, much appreciated..

If I can change the date/time format to a format where it is only one
string
what will be java syntax for definign the option within my application

e.g
inal Option persistDataOption =
 OptionBuilder.withArgName("persist").hasOptionalArgs(3)
 hasArg().withDescription("Persist Data with Scheduling")
 .create("-p");

I cant seem to get the above line correct...

I want to define an option that has
A. 3 options... name> | <Time> | <Boolean
B. 1 Mandatory ... name
C. 2 optional params Time , Boolean

Can you help me define this option correctly first, then I can move on
and
worry about the  Date/Time being 2 strings

Regards
jhon


-----Original Message-----
From: Russel Winder [mailto:[hidden email]]
Sent: 29 May 2008 20:25
To: Commons Users List
Subject: Re: Common CLi Usage

* PGP Signed by an unknown key: 05/29/2008 at 09:24:30 PM On Thu,
2008-05-29 at 12:58 +0200, John O'Sullivan wrote:

> myApp -p [<name> | <Time> | <Boolean>] -a XXX -d xxx -f XXX
>
> where time is of the format 'YYYY-MM-DD HH:MM:SS'
> Note
> 1. There is a space between the "YYYY-MM-DD"  and the "HH:MM:SS"(does
> this mean the CLI Parser will see 2 parameters ) 2. The <time> and
> <boolean> parameters are optional.
> 3. The <name> parameter is mandatory when using the -p option
>
> I am using the Commons Cli API..
> I am trying to define the option as follows but this obviously isnt
> correct
>
> final Option persistDataOption =
> OptionBuilder.withArgName("persist").hasOptionalArgs(3)
> hasArg().withDescription("Persist Data with Scheduling")
> .create(CLIOption.PERSIST_DATA.getOptionString());
> where
> CLIOption.PERSIST_DATA.getOptionString()) will return the "-p" option
>
> Can someone please show me how to define this command line option
> correctly please

I don't have an immediate answer for you I'm afraid.  The reason for
replying is to note that this looks almost, but not quite exactly, like
an ISO 8601 date -- the differences are going to be very irritating I
suspect.  The though struck me that ISO 8601 date should be a known
construct to any CLI system.  Of course, Java's current date system is
effectively rubbish, and JodaTime isn't yet standard.

I suspect the only way forward for the moment is to quote the date
string as a parameter or use the full no space ISO 8601 format (i.e.
replace space with T), and then ship the string to a JodaTime function
for parsing.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077
* Unknown Key
* 0x856F058D


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Common CLi Usage

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John,

John O'Sullivan wrote:
| If I can change the date/time format to a format where it is only one
| string
| what will be java syntax for definign the option within my application

Sorry to poke my nose into what looks like a rather long-running
discussion, but it occurs to me that calling your program from the
command-line with quotes around the entire timestamp (both date and
time) would make the entire parameter appear as one -- with or without
the space. Something like:

| myApp -p [<name> | <Time> | <Boolean>] -a XXX -d xxx -f XXX

myApp -p '2008-05-29 16:54:25'

Does that help you with your "space" problem?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg/GDMACgkQ9CaO5/Lv0PAtuwCeKz11MAM2KultB/c8664q1Mwm
rzYAoLQrQs60OzKEP4MFAIOI+bUlGEIl
=8QoN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Common CLi Usage

John O'Sullivan-2
Hi,
Feel free to poke your nose in anytime ;>

Thanks, thats an idea I will try for the "space problem"..

The Other problem is I dont have the correct syntax for the folowing
line which defines teh option.Do you know the correct java syntax for
this which provides the functionality I require

final Option persistDataOption =
OptionBuilder.withArgName("persist").hasOptionalArgs(3)
 hasArg().withDescription("Persist Data with Scheduling")
.create("-p");

This is not correct?

jhon

-----Original Message-----
From: Christopher Schultz [mailto:[hidden email]]
Sent: 29 May 2008 21:55
To: Commons Users List
Subject: Re: Common CLi Usage

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John,

John O'Sullivan wrote:
| If I can change the date/time format to a format where it is only one
| string what will be java syntax for definign the option within my
| application

Sorry to poke my nose into what looks like a rather long-running
discussion, but it occurs to me that calling your program from the
command-line with quotes around the entire timestamp (both date and
time) would make the entire parameter appear as one -- with or without
the space. Something like:

| myApp -p [<name> | <Time> | <Boolean>] -a XXX -d xxx -f XXX

myApp -p '2008-05-29 16:54:25'

Does that help you with your "space" problem?

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkg/GDMACgkQ9CaO5/Lv0PAtuwCeKz11MAM2KultB/c8664q1Mwm
rzYAoLQrQs60OzKEP4MFAIOI+bUlGEIl
=8QoN
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Common CLi Usage

Christopher Schultz-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

John,

John O'Sullivan wrote:
| Hi,
| Feel free to poke your nose in anytime ;>
|
| Thanks, thats an idea I will try for the "space problem"..
|
| The Other problem is I dont have the correct syntax for the folowing
| line which defines teh option. Do you know the correct java syntax for
| this which provides the functionality I require

Heh.. that's the thing... I have no commons-cli experience at all, which
makes my nose somewhat unwelcome ;)

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkhAhNcACgkQ9CaO5/Lv0PDi+ACeN6o3sgJfUT5WnaBrUaoIVOqS
Ui0AoJ/RpEYRw6FwCVKXOF4AjRlP4kDB
=cp1f
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

RE: Common CLi Usage

Russel Winder-2
In reply to this post by John O'Sullivan-2
John,

On Thu, 2008-05-29 at 22:10 +0200, John O'Sullivan wrote:
> Hi russel,
> Thanks for your reply, much appreciated..

No problem.

If you check the email histories, you'll probably spot that Commons CLI
is a bit of a hobby horse for me.  Groovy and Gant both use it but
(unfortunately) it is very broken -- 1.0 just about works, 1.1 has a
collection of great bug fixes thanks to Hen and Brian, but is
fundamentally broken :-(,  2.x got played with and then the development
team evaporated and left the whole package in limbo.
   

> If I can change the date/time format to a format where it is only one
> string
> what will be java syntax for definign the option within my application
>
> e.g
> inal Option persistDataOption =
>  OptionBuilder.withArgName("persist").hasOptionalArgs(3)
>  hasArg().withDescription("Persist Data with Scheduling")
>  .create("-p");
>
> I cant seem to get the above line correct...
>
> I want to define an option that has
> A. 3 options... name> | <Time> | <Boolean
> B. 1 Mandatory ... name
> C. 2 optional params Time , Boolean
>
> Can you help me define this option correctly first, then I can move on
> and
> worry about the  Date/Time being 2 strings
To be honest I don't think I would even try and attempt using Commons
CLI or any other CLI package to handle the parsing of the option itself.
I would use the options system to get a simple string and then process
that string with a data parser, probably JodaTime until JSR 310 becomes
standard.

So accept "-p" as a simple option with a single string parameter and
then when you find you have one drag up the data processing actions and
handle things then.

--
Russel.
====================================================
Dr Russel Winder                 Partner

Concertant LLP                   t: +44 20 7585 2200, +44 20 7193 9203
41 Buckmaster Road,              f: +44 8700 516 084
London SW11 1EN, UK.             m: +44 7770 465 077

signature.asc (196 bytes) Download Attachment