Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 72168 invoked from network); 4 Jun 2009 19:55:18 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 4 Jun 2009 19:55:18 -0000 Received: (qmail 19228 invoked by uid 500); 4 Jun 2009 19:55:29 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 19108 invoked by uid 500); 4 Jun 2009 19:55:29 -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 19097 invoked by uid 99); 4 Jun 2009 19:55:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Jun 2009 19:55:29 +0000 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; Thu, 04 Jun 2009 19:55:27 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 57A4A234C004 for ; Thu, 4 Jun 2009 12:55:07 -0700 (PDT) Message-ID: <913831743.1244145307344.JavaMail.jira@brutus> Date: Thu, 4 Jun 2009 12:55:07 -0700 (PDT) From: "Michael Heuer (JIRA)" To: issues@commons.apache.org Subject: [jira] Issue Comment Edited: (CLI-179) Needs "standalone" options that can be used even if required options are not set In-Reply-To: <457440463.1241108550347.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CLI-179?page=3Dcom.atlassian.ji= ra.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=3D1271638= 0#action_12716380 ]=20 Michael Heuer edited comment on CLI-179 at 6/4/09 12:53 PM: ------------------------------------------------------------ This appears to be the same problem I posted about to commons-user earlier.= I will give your workaround a try, Emmanuel. http://mail-archives.apache.org/mod_mbox/commons-user/200903.mbox/%3CPine.G= SO.4.44.0903121240051.16891-100000@shell3.shore.net%3E was (Author: heuermh): This appears to be the same problem I posted about to commons-user earl= ier. I will give your workaround a try, Emmanuel. --- Date: Thu, 12 Mar 2009 13:02:44 -0500 (EST) To: user@commons.apache.org Subject: [CLI1.x] help option doesn't work if there is a required option Hello, My use case is -h,--help text prints to STDOUT and command line errors print to STDERR. This works fine in the simple case Options options =3D new Options(); HelpFormatter helpFormatter =3D new HelpFormatter(); Option help =3D new Option("h", "help", false, "print help text to STDOUT")= ; help.setRequired(false); options.addOption(help); try { CommandLineParser parser =3D new PosixParser(); CommandLine commandLine =3D parser.parse(options, args); if (commandLine.hasOption(help.getOpt())) { helpFormatter.printHelp(... } ... } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(new PrintWriter(System.err, true), ... } But if there is a missing required option, the help part is unreachable, since a MissingOptionException is thrown Options options =3D new Options(); HelpFormatter helpFormatter =3D new HelpFormatter(); Option help =3D new Option("h", "help", false, "print help text to STDOUT")= ; help.setRequired(false); Option foo =3D new Option(...); foo.setRequired(true); options.addOption(help); options.addOption(foo); try { CommandLineParser parser =3D new PosixParser(); CommandLine commandLine =3D parser.parse(options, args); if (commandLine.hasOption(help.getOpt())) { helpFormatter.printHelp(... } ... } catch (ParseException e) { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(new PrintWriter(System.err, true), ... } I could move the help part to the catch block, but there is no way to query whether the help option was found. catch (ParseException e) { if ( help was found ) { helpFormatter.printHelp(... } else { System.err.println(e.getMessage() + "\n"); helpFormatter.printHelp(new PrintWriter(System.err, true), ... } } =20 > Needs "standalone" options that can be used even if required options are = not set > -------------------------------------------------------------------------= ------- > > Key: CLI-179 > URL: https://issues.apache.org/jira/browse/CLI-179 > Project: Commons CLI > Issue Type: Improvement > Components: Parser > Affects Versions: 1.2 > Reporter: Jo=C3=ABl Royer > Fix For: 1.4 > > > it is currently impossible to have options like "help" or "version" if we= also have some required options. The parsing results in an error "Missing = parameters". > But for an "help" or "version" option, it would be usefull to display the= wanted information, even if required options are not set. --=20 This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.