You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Mike Luo <ML...@ph.com> on 2002/12/05 18:06:53 UTC

[CLI] problem using cli

I've encounted two problems with CLI:

1. option with argument cannot be placed in the end of the command line. For
example,

    cli -buildfile connect.xml -debug -emacs -help -logger com.ph.log.Log

    Exception in thread "main"
org.apache.commons.cli.MissingArgumentException: no argument for:logger
        at org.apache.commons.cli.Parser.processArgs(Parser.java:239)
        at org.apache.commons.cli.Parser.processOption(Parser.java:277)
        at org.apache.commons.cli.Parser.parse(Parser.java:170)
        at org.apache.commons.cli.Parser.parse(Parser.java:114)
        at com.ph.econnection.command.console.Cli.main(Cli.java:158)

2. the trailing arguments are not retrievable by CommandLine.getArgs(). For
example,

   cli -buildfile connect.xml -debug -emacs -help a1 a2 a3

   a1, a2 a3 can not be retrieved by calling CommandLine.getArgs().

I'll attach my test program. Pls help. Thanks.

-Mike

 <<Cli.java>> 
 
*************************************************************************
PRIVILEGED AND CONFIDENTIAL: This communication, including attachments, is
for the exclusive use of addressee and may contain proprietary, confidential
and/or privileged information.  If you are not the intended recipient, any
use, copying, disclosure, dissemination or distribution is strictly
prohibited.  If you are not the intended recipient, please notify the sender
immediately by return e-mail, delete this communication and destroy all
copies.
************************************************************************* 

Re: [CLI] problem using cli

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

Thanks for the reporting this issue.  I'll have a peek
at it when I get a chance.

-John K

On Thu, 2002-12-05 at 17:06, Mike Luo wrote:
> I've encounted two problems with CLI:
> 
> 1. option with argument cannot be placed in the end of the command line. For
> example,
> 
>     cli -buildfile connect.xml -debug -emacs -help -logger com.ph.log.Log
> 
>     Exception in thread "main"
> org.apache.commons.cli.MissingArgumentException: no argument for:logger
>         at org.apache.commons.cli.Parser.processArgs(Parser.java:239)
>         at org.apache.commons.cli.Parser.processOption(Parser.java:277)
>         at org.apache.commons.cli.Parser.parse(Parser.java:170)
>         at org.apache.commons.cli.Parser.parse(Parser.java:114)
>         at com.ph.econnection.command.console.Cli.main(Cli.java:158)
> 
> 2. the trailing arguments are not retrievable by CommandLine.getArgs(). For
> example,
> 
>    cli -buildfile connect.xml -debug -emacs -help a1 a2 a3
> 
>    a1, a2 a3 can not be retrieved by calling CommandLine.getArgs().
> 
> I'll attach my test program. Pls help. Thanks.
> 
> -Mike
> 
>  <<Cli.java>> 
>  
> *************************************************************************
> PRIVILEGED AND CONFIDENTIAL: This communication, including attachments, is
> for the exclusive use of addressee and may contain proprietary, confidential
> and/or privileged information.  If you are not the intended recipient, any
> use, copying, disclosure, dissemination or distribution is strictly
> prohibited.  If you are not the intended recipient, please notify the sender
> immediately by return e-mail, delete this communication and destroy all
> copies.
> ************************************************************************* 
> 
> ______________________________________________________________________
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
John Keyes <jb...@mac.com>


RE: problem wth CLI

Posted by Christophe Marcourt <ch...@mondeca.com>.
Yes I use the 1.0 version and I don't get yet the CVS source...
I will update the sources of CLI, so.

Thank you

Christophe Marcourt
Mondeca
Ingénieur R&D
3, Cité Nollez. 75018 Paris
Phone : +33 1 44 92 35 03
Mobile : +33 6 14 48 65 66
Fax : +33 1 44 92 02 59
http://www.mondeca.com/fr
ICQ : #119811844

-----Message d'origine-----
De : John Keyes [mailto:jbjk@mac.com]
Envoyé : jeudi 12 décembre 2002 15:05
À : Jakarta Commons Users List
Objet : Re: problem wth CLI

Hi Christophe,

Are you using the 1.0 version?  A fix for this bug was
committed a few weeks ago to CVS.  I'll test this when
I get a chance.

-John K

On Thu, 2002-12-12 at 13:59, Christophe Marcourt wrote:
> This is weird. I create two options (noChecking and noCreation) with a
long
> option and no short options.
> When I use the "-h" option to display the usage message, I only see the
> "--no-creation" option. Where is my "--no-checking" option ??? (;-))
>
> I know how to fix this bug. I just have to create these two options with a
> short option as well, but I don't want short options for these options...
>
> Below my sample code :
>
> public class Main() {
> ...
>
> public void createOptions() {
> Option noChecking =
> OptionBuilder.withLongOpt(Main.NO_CHECKING_OPTION).withDescription("add
this
> option if you don't want to check \nall the topic ref from the xtm file.
The
> checking process will be faster.").create();
>         Option noCreation =
> OptionBuilder.withLongOpt(Main.NO_CREATION_OPTION).withDescription("add
this
> option if you don't want to create\n all the topics and
> classifications.").create();
> Option wscr =
>
OptionBuilder.withArgName("id1,id2,id3,...").hasArgs().withValueSeparator(Ma
> in.ID_SEPARATOR).withDescription("required. A comma separated list of
> consultation rights
> id.").isRequired().create(Main.CONSULTATION_RIGHT_LIST_OPTION);
>         wscr.isRequired();
>         Option wser =
>
OptionBuilder.withArgName("id1,id2,id3,...").hasArgs().withValueSeparator(Ma
> in.ID_SEPARATOR).withDescription("required. A comma separated list of
> edition rights id.").isRequired().create(Main.EDITION_RIGHT_LIST_OPTION);
>         wser.isRequired();
>         Option wsuser =
>
OptionBuilder.withArgName("login/password").hasArgs(2).withValueSeparator(Ma
> in.LOGIN_PASSWORD_SEPARATOR).withDescription("required. The user's
> authentication.").isRequired().create(Main.USER_OPTION);
>         wsuser.isRequired();
>         Option lang = OptionBuilder.withArgName("language's
> id").hasArg().withDescription("the language used to create the new
objects.
> If ommited, the data items created will be available for all
> languages.").create(Main.LANG_OPTION);
>         Option help = new Option(Main.HELP_SHORT_OPTION,
> Main.HELP_LONG_OPTION, false, "print this message");
>         Option logLevel =
> OptionBuilder.withArgName("level").hasArg().withDescription("the console
log
> level. By default fatal.\ndebug : fine-grained informational events that
are
> most useful to debug an application\ninfo : informational messages that
> highlight the progress of the application at coarse-grained level\nwarn :
> potentially harmful situations\nerror : error events that might still
allow
> the application to continue running\nfatal : very severe error events that
> will presumably lead the application to abort\noff : turn off the
>
trace").withLongOpt(Main.LOG_LEVEL_LONG_OPTION).create(Main.LOG_LEVEL_SHORT_
> OPTION);
>
>         this.options = new Options();
>         this.options.addOption(noChecking);
>         this.options.addOption(noCreation);
>         this.options.addOption(wscr);
>         this.options.addOption(wser);
>         this.options.addOption(wsuser);
>         this.options.addOption(lang);
>         this.options.addOption(help);
>         this.options.addOption(logLevel);
> }
> ...
> }
>
>
> Here is my usage message with the "--help" option :
>
> ...
> options :
>     --no-creation          add this option if you don't want to create
>                            all the topics and classifications.
>  -ll,--log-level <level>   the console log level. By default fatal.
>                            debug : fine-grained informational events that
> are most useful to debug an
>                            application
>                            info : informational messages that highlight
the
> progress of the
>                            application at coarse-grained level
>                            warn : potentially harmful situations
>                            error : error events that might still allow the
> application to continue
>                            running
>                            fatal : very severe error events that will
> presumably lead the application
>                            to abort
>                            off : turn off the trace
>  -crl <id1,id2,id3,...>    required. A comma separated list of
>                            consultation rights id.
>  -erl <id1,id2,id3,...>    required. A comma separated list of edition
>                            rights id.
>  -h,--help                 print this message
>  -lang <language's id>     the language used to create the new objects. If
>                            ommited, the data items created will be
available
> for all languages.
>  -user <login/password>    required. The user's authentication.
> ...
>
> Any idea ??
>
> Christophe Marcourt
> Mondeca
> Ingenieur R&D
> 3, Cite Nollez. 75018 Paris
> Phone : +33 1 44 92 35 03
> Mobile : +33 6 14 48 65 66
> Fax : +33 1 44 92 02 59
> http://www.mondeca.com/fr
> ICQ : #119811844
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
John Keyes <jb...@mac.com>


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


Re: problem wth CLI

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

Are you using the 1.0 version?  A fix for this bug was
committed a few weeks ago to CVS.  I'll test this when
I get a chance.

-John K

On Thu, 2002-12-12 at 13:59, Christophe Marcourt wrote:
> This is weird. I create two options (noChecking and noCreation) with a long
> option and no short options.
> When I use the "-h" option to display the usage message, I only see the
> "--no-creation" option. Where is my "--no-checking" option ??? (;-))
> 
> I know how to fix this bug. I just have to create these two options with a
> short option as well, but I don't want short options for these options...
> 
> Below my sample code :
> 
> public class Main() {
> ...
> 
> public void createOptions() {
> Option noChecking =
> OptionBuilder.withLongOpt(Main.NO_CHECKING_OPTION).withDescription("add this
> option if you don't want to check \nall the topic ref from the xtm file. The
> checking process will be faster.").create();
>         Option noCreation =
> OptionBuilder.withLongOpt(Main.NO_CREATION_OPTION).withDescription("add this
> option if you don't want to create\n all the topics and
> classifications.").create();
> Option wscr =
> OptionBuilder.withArgName("id1,id2,id3,...").hasArgs().withValueSeparator(Ma
> in.ID_SEPARATOR).withDescription("required. A comma separated list of
> consultation rights
> id.").isRequired().create(Main.CONSULTATION_RIGHT_LIST_OPTION);
>         wscr.isRequired();
>         Option wser =
> OptionBuilder.withArgName("id1,id2,id3,...").hasArgs().withValueSeparator(Ma
> in.ID_SEPARATOR).withDescription("required. A comma separated list of
> edition rights id.").isRequired().create(Main.EDITION_RIGHT_LIST_OPTION);
>         wser.isRequired();
>         Option wsuser =
> OptionBuilder.withArgName("login/password").hasArgs(2).withValueSeparator(Ma
> in.LOGIN_PASSWORD_SEPARATOR).withDescription("required. The user's
> authentication.").isRequired().create(Main.USER_OPTION);
>         wsuser.isRequired();
>         Option lang = OptionBuilder.withArgName("language's
> id").hasArg().withDescription("the language used to create the new objects.
> If ommited, the data items created will be available for all
> languages.").create(Main.LANG_OPTION);
>         Option help = new Option(Main.HELP_SHORT_OPTION,
> Main.HELP_LONG_OPTION, false, "print this message");
>         Option logLevel =
> OptionBuilder.withArgName("level").hasArg().withDescription("the console log
> level. By default fatal.\ndebug : fine-grained informational events that are
> most useful to debug an application\ninfo : informational messages that
> highlight the progress of the application at coarse-grained level\nwarn :
> potentially harmful situations\nerror : error events that might still allow
> the application to continue running\nfatal : very severe error events that
> will presumably lead the application to abort\noff : turn off the
> trace").withLongOpt(Main.LOG_LEVEL_LONG_OPTION).create(Main.LOG_LEVEL_SHORT_
> OPTION);
> 
>         this.options = new Options();
>         this.options.addOption(noChecking);
>         this.options.addOption(noCreation);
>         this.options.addOption(wscr);
>         this.options.addOption(wser);
>         this.options.addOption(wsuser);
>         this.options.addOption(lang);
>         this.options.addOption(help);
>         this.options.addOption(logLevel);
> }
> ...
> }
> 
> 
> Here is my usage message with the "--help" option :
> 
> ...
> options :
>     --no-creation          add this option if you don't want to create
>                            all the topics and classifications.
>  -ll,--log-level <level>   the console log level. By default fatal.
>                            debug : fine-grained informational events that
> are most useful to debug an
>                            application
>                            info : informational messages that highlight the
> progress of the
>                            application at coarse-grained level
>                            warn : potentially harmful situations
>                            error : error events that might still allow the
> application to continue
>                            running
>                            fatal : very severe error events that will
> presumably lead the application
>                            to abort
>                            off : turn off the trace
>  -crl <id1,id2,id3,...>    required. A comma separated list of
>                            consultation rights id.
>  -erl <id1,id2,id3,...>    required. A comma separated list of edition
>                            rights id.
>  -h,--help                 print this message
>  -lang <language's id>     the language used to create the new objects. If
>                            ommited, the data items created will be available
> for all languages.
>  -user <login/password>    required. The user's authentication.
> ...
> 
> Any idea ??
> 
> Christophe Marcourt
> Mondeca
> Ingenieur R&D
> 3, Cite Nollez. 75018 Paris
> Phone : +33 1 44 92 35 03
> Mobile : +33 6 14 48 65 66
> Fax : +33 1 44 92 02 59
> http://www.mondeca.com/fr
> ICQ : #119811844
> 
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
John Keyes <jb...@mac.com>


problem wth CLI

Posted by Christophe Marcourt <ch...@mondeca.com>.
This is weird. I create two options (noChecking and noCreation) with a long
option and no short options.
When I use the "-h" option to display the usage message, I only see the
"--no-creation" option. Where is my "--no-checking" option ??? (;-))

I know how to fix this bug. I just have to create these two options with a
short option as well, but I don't want short options for these options...

Below my sample code :

public class Main() {
...

public void createOptions() {
Option noChecking =
OptionBuilder.withLongOpt(Main.NO_CHECKING_OPTION).withDescription("add this
option if you don't want to check \nall the topic ref from the xtm file. The
checking process will be faster.").create();
        Option noCreation =
OptionBuilder.withLongOpt(Main.NO_CREATION_OPTION).withDescription("add this
option if you don't want to create\n all the topics and
classifications.").create();
Option wscr =
OptionBuilder.withArgName("id1,id2,id3,...").hasArgs().withValueSeparator(Ma
in.ID_SEPARATOR).withDescription("required. A comma separated list of
consultation rights
id.").isRequired().create(Main.CONSULTATION_RIGHT_LIST_OPTION);
        wscr.isRequired();
        Option wser =
OptionBuilder.withArgName("id1,id2,id3,...").hasArgs().withValueSeparator(Ma
in.ID_SEPARATOR).withDescription("required. A comma separated list of
edition rights id.").isRequired().create(Main.EDITION_RIGHT_LIST_OPTION);
        wser.isRequired();
        Option wsuser =
OptionBuilder.withArgName("login/password").hasArgs(2).withValueSeparator(Ma
in.LOGIN_PASSWORD_SEPARATOR).withDescription("required. The user's
authentication.").isRequired().create(Main.USER_OPTION);
        wsuser.isRequired();
        Option lang = OptionBuilder.withArgName("language's
id").hasArg().withDescription("the language used to create the new objects.
If ommited, the data items created will be available for all
languages.").create(Main.LANG_OPTION);
        Option help = new Option(Main.HELP_SHORT_OPTION,
Main.HELP_LONG_OPTION, false, "print this message");
        Option logLevel =
OptionBuilder.withArgName("level").hasArg().withDescription("the console log
level. By default fatal.\ndebug : fine-grained informational events that are
most useful to debug an application\ninfo : informational messages that
highlight the progress of the application at coarse-grained level\nwarn :
potentially harmful situations\nerror : error events that might still allow
the application to continue running\nfatal : very severe error events that
will presumably lead the application to abort\noff : turn off the
trace").withLongOpt(Main.LOG_LEVEL_LONG_OPTION).create(Main.LOG_LEVEL_SHORT_
OPTION);

        this.options = new Options();
        this.options.addOption(noChecking);
        this.options.addOption(noCreation);
        this.options.addOption(wscr);
        this.options.addOption(wser);
        this.options.addOption(wsuser);
        this.options.addOption(lang);
        this.options.addOption(help);
        this.options.addOption(logLevel);
}
...
}


Here is my usage message with the "--help" option :

...
options :
    --no-creation          add this option if you don't want to create
                           all the topics and classifications.
 -ll,--log-level <level>   the console log level. By default fatal.
                           debug : fine-grained informational events that
are most useful to debug an
                           application
                           info : informational messages that highlight the
progress of the
                           application at coarse-grained level
                           warn : potentially harmful situations
                           error : error events that might still allow the
application to continue
                           running
                           fatal : very severe error events that will
presumably lead the application
                           to abort
                           off : turn off the trace
 -crl <id1,id2,id3,...>    required. A comma separated list of
                           consultation rights id.
 -erl <id1,id2,id3,...>    required. A comma separated list of edition
                           rights id.
 -h,--help                 print this message
 -lang <language's id>     the language used to create the new objects. If
                           ommited, the data items created will be available
for all languages.
 -user <login/password>    required. The user's authentication.
...

Any idea ??

Christophe Marcourt
Mondeca
Ingenieur R&D
3, Cite Nollez. 75018 Paris
Phone : +33 1 44 92 35 03
Mobile : +33 6 14 48 65 66
Fax : +33 1 44 92 02 59
http://www.mondeca.com/fr
ICQ : #119811844



Re: [CLI] problem using cli

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

Sorry for the delay in responding to your email, I have a bunch of
email to catch up on :-(

With regards to your two problems I have just run the two examples
you specify using the attached test case and have encountered no
problems at all.

Can you tell me what version of CLI you are using?  Is it built from
CVS or is it the 1.0 release?

Cheers,
-John K

On Thursday, Dec 5, 2002, at 17:06 Europe/Dublin, Mike Luo wrote:

> I've encounted two problems with CLI:
>
> 1. option with argument cannot be placed in the end of the command  
> line. For
> example,
>
>     cli -buildfile connect.xml -debug -emacs -help -logger  
> com.ph.log.Log
>
>     Exception in thread "main"
> org.apache.commons.cli.MissingArgumentException: no argument for:logger
>         at org.apache.commons.cli.Parser.processArgs(Parser.java:239)
>         at org.apache.commons.cli.Parser.processOption(Parser.java:277)
>         at org.apache.commons.cli.Parser.parse(Parser.java:170)
>         at org.apache.commons.cli.Parser.parse(Parser.java:114)
>         at com.ph.econnection.command.console.Cli.main(Cli.java:158)
>
> 2. the trailing arguments are not retrievable by  
> CommandLine.getArgs(). For
> example,
>
>    cli -buildfile connect.xml -debug -emacs -help a1 a2 a3
>
>    a1, a2 a3 can not be retrieved by calling CommandLine.getArgs().
>
> I'll attach my test program. Pls help. Thanks.
>
> -Mike
>
>  <<Cli.java>>
>
> *********************************************************************** 
> **
> PRIVILEGED AND CONFIDENTIAL: This communication, including  
> attachments, is
> for the exclusive use of addressee and may contain proprietary,  
> confidential
> and/or privileged information.  If you are not the intended recipient,  
> any
> use, copying, disclosure, dissemination or distribution is strictly
> prohibited.  If you are not the intended recipient, please notify the  
> sender
> immediately by return e-mail, delete this communication and destroy all
> copies.
> *********************************************************************** 
> **
> <Cli.java>--
> To unsubscribe, e-mail:    
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:  
> <ma...@jakarta.apache.org>
- - - - - - - - - - - - - - - - - - - - - - -
Jakarta Commons CLI
http://jakarta.apache.org/commons/cli