You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2006/03/29 12:59:47 UTC
DO NOT REPLY [Bug 39140] New: - [cli] A weakness of parser
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39140>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39140
Summary: [cli] A weakness of parser
Product: Commons
Version: unspecified
Platform: All
OS/Version: other
Status: NEW
Severity: normal
Priority: P2
Component: CLI
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: amro.alakkad@googlemail.com
I found a weakness of Jakarta Commons CLI and want to explain it with a simple
example:
Our program provides 2 options:
1. -a or --algo <name>: The -a option requires an argument.
2. -k or --key <value>: The -k option requires an argument too.
a)
If you pass the following command line arguments everything will be ok:
-a Caesar �k A
After evaluation:
� �Caesar� is the parameter of the -a option and
� �A� is the parameter of the -k option.
b)
However an org.apache.commons.cli.MissingArgumentException: no argument for:k is
thrown if you pass the following input:
-a Caesar -k a
The Parser assumes that the argument �a� after the -k option, is the -a option
missing the hyphen. At the end of this description there is Java code for
executing this problem.
Information:
The handling of this command line
-a Caesar -k a
works in Getopt without any problem:
� �Caesar� is the parameter of the -a option and
� �a� of the -k option.
After parsing a valid option Getopt always takes the next (available) command
line argument as the option�s parameter if the option requires an argument �
means if you pass to the command line
�k -a Caesar
After evaluation:
� �a� is the parameter of the -k option
� the �Caesar� argument is just ignored
If the option�s parameter (<value>) represents an optional argument the next
argument is not required, if it represents a valid option � means if you pass to
the command line
�k -a Caesar
After evaluation:
� �Caesar� is the parameter of the -a option
� k option is set without a parameter � in this case a default value makes sense.
Last but not least here is the code snippet for the CLI Test:
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
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 TestCommonsCLI {
/**
* @param args
*/
public static void main(String[] args) {
Options options = new Options();
Option algorithm = new Option("a" , "algo", true, "the algorithm which it to
perform executing");
algorithm.setArgName("algorithm name");
options.addOption(algorithm);
Option key = new Option("k" , "key", true, "the key the setted algorithm uses
to process");
algorithm.setArgName("value");
options.addOption(key);
CommandLineParser parser = new PosixParser();
try {
CommandLine line = parser.parse( options, args);
if(line.hasOption('a')){
System.out.println("algo: "+ line.getOptionValue( "a" ));
}
if(line.hasOption('k')){
System.out.println("key: " + line.getOptionValue('k'));
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
DO NOT REPLY [Bug 39140] - [cli] A weakness of parser
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39140>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39140
------- Additional Comments From bayard@apache.org 2007-05-23 01:48 -------
Nudge to make comments on the JIRA rather than Bugzilla - I know it sucks that
we don't have a good way of closing things in Bugzilla. :(
http://issues.apache.org/jira/browse/CLI-71
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
DO NOT REPLY [Bug 39140] - [cli] A weakness of parser
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39140>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39140
amro.alakkad@googlemail.com changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #17999|code which can us for |TestCommonsCLI.java is the
description|executing the described |code for executing the
|problem |described problem
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
DO NOT REPLY [Bug 39140] - [cli] A weakness of parser
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39140>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39140
------- Additional Comments From amro.alakkad@googlemail.com 2006-03-29 12:04 -------
Created an attachment (id=17999)
--> (http://issues.apache.org/bugzilla/attachment.cgi?id=17999&action=view)
code which can us for executing the described problem
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
DO NOT REPLY [Bug 39140] - [cli] A weakness of parser
Posted by bu...@apache.org.
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=39140>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=39140
------- Additional Comments From amro.alakkad@googlemail.com 2007-05-22 15:23 -------
>>Amro didn't flag the 'license for asf inclusion' checkbox<<
Sorry.
>>JUnit test based on Amro's description. As expected, it fails.<<
:(. When will this bug be fixed (approximately)?
Will this weakness exist, in the newer version, too?
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org