Return-Path: Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: (qmail 87864 invoked from network); 4 Jun 2008 16:16:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jun 2008 16:16:10 -0000 Received: (qmail 32873 invoked by uid 500); 4 Jun 2008 16:16:11 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 32793 invoked by uid 500); 4 Jun 2008 16:16:11 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 32782 invoked by uid 99); 4 Jun 2008 16:16:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jun 2008 09:16:11 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jun 2008 16:15:23 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 250AD234C12E for ; Wed, 4 Jun 2008 09:15:45 -0700 (PDT) Message-ID: <357298023.1212596145150.JavaMail.jira@brutus> Date: Wed, 4 Jun 2008 09:15:45 -0700 (PDT) From: "Emmanuel Bourg (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (CLI-158) deafult arguments only works if no arguments are submitted In-Reply-To: <2119092767.1212589425263.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CLI-158?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12602333#action_12602333 ] Emmanuel Bourg commented on CLI-158: ------------------------------------ What is the use case for a default value per argument, instead of a default list of values if no argument is specified ? The current behavior seems more intuitive to me. > deafult arguments only works if no arguments are submitted > ---------------------------------------------------------- > > Key: CLI-158 > URL: https://issues.apache.org/jira/browse/CLI-158 > Project: Commons CLI > Issue Type: Bug > Components: CLI-2.x > Affects Versions: 2.0 > Reporter: Andrew Oxenburgh > Fix For: 2.0 > > Original Estimate: 2h > Remaining Estimate: 2h > > When using multple arguments and defaults, the behaviour is counter-intuitive and will only pick up a default if no args are passed in. > For instance in the code below I have set up so 0, 1, or 2 args may bve accepted, with defaults 100 and 1000. > I expect it to behave as follows. > 1. for 2 args, 1 and 2 the values should be 1 and 2. This works as expected. > 2. for 0 args passed in the values should be 100 and 1000, picking up both of the defaults. This works as expected > 3. for 1 arg passed in the values should be 1 and 1000, so the second argument picks up the second default value. The valuse become just 1, which is not as expected.. > Currently, in the second case will only return 1 and ignore the defaults. > public void testSingleOptionSingleArgument() throws Exception { > String defaulValue1 = "100"; > String defaultValue2 = "1000"; > final DefaultOptionBuilder obuilder = new DefaultOptionBuilder(); > final ArgumentBuilder abuilder = new ArgumentBuilder(); > final GroupBuilder gbuilder = new GroupBuilder(); > DefaultOption bOption = obuilder.withShortName("b") > .withLongName("b") > .withArgument(abuilder.withName("b") > .withMinimum(0) > .withMaximum(2) > .withDefault(defaulValue1) > .withDefault(defaultValue2) > .create()) > .create(); > Group options = gbuilder > .withName("options") > .withOption(bOption) > .create(); > Parser parser = new Parser(); > parser.setHelpTrigger("--help"); > parser.setGroup(options); > String enteredValue1 = "1"; > String[] args = new String[]{"-b", enteredValue1}; > CommandLine cl = parser.parse(args); > CommandLine cmd = cl; > assertNotNull(cmd); > List b = cmd.getValues("-b"); > assertEquals("[" + enteredValue1 + "]", b + ""); > } -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.