Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 75134 invoked from network); 6 Jun 2007 08:01:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Jun 2007 08:01:44 -0000 Received: (qmail 60697 invoked by uid 500); 6 Jun 2007 08:01:45 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 60634 invoked by uid 500); 6 Jun 2007 08:01:45 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 60623 invoked by uid 500); 6 Jun 2007 08:01:45 -0000 Received: (qmail 60620 invoked by uid 99); 6 Jun 2007 08:01:45 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jun 2007 01:01:45 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 06 Jun 2007 01:01:40 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 7454E1A981A; Wed, 6 Jun 2007 01:01:20 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r544762 - in /jakarta/commons/proper/cli/branches/cli-1.0.x/src: java/org/apache/commons/cli/HelpFormatter.java test/org/apache/commons/cli/BugsTest.java test/org/apache/commons/cli/TestHelpFormatter.java Date: Wed, 06 Jun 2007 08:01:20 -0000 To: commons-cvs@jakarta.apache.org From: bayard@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070606080120.7454E1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bayard Date: Wed Jun 6 01:01:19 2007 New Revision: 544762 URL: http://svn.apache.org/viewvc?view=rev&rev=544762 Log: Applying Brian Egge's enhancement from CLI-131 Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java?view=diff&rev=544762&r1=544761&r2=544762 ============================================================================== --- jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java (original) +++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/java/org/apache/commons/cli/HelpFormatter.java Wed Jun 6 01:01:19 2007 @@ -442,8 +442,10 @@ // temp variable Option option; + List optList = new ArrayList(options.getOptions()); + Collections.sort(optList, new OptionComparator()); // iterate over the options - for (Iterator i = options.getOptions().iterator(); i.hasNext();) + for (Iterator i = optList.iterator(); i.hasNext();) { // get the next Option option = (Option) i.next(); @@ -503,8 +505,10 @@ buff.append("["); } + List optList = new ArrayList(group.getOptions()); + Collections.sort(optList, new OptionComparator()); // for each option in the OptionGroup - for (Iterator i = group.getOptions().iterator(); i.hasNext();) + for (Iterator i = optList.iterator(); i.hasNext();) { // whether the option is required or not is handled at group level appendOption(buff, (Option) i.next(), true); Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java?view=diff&rev=544762&r1=544761&r2=544762 ============================================================================== --- jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java (original) +++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/BugsTest.java Wed Jun 6 01:01:19 2007 @@ -466,8 +466,8 @@ StringWriter out = new StringWriter(); formatter.printHelp(new PrintWriter(out),80,"commandline","header",mOptions,2,2,"footer",true); assertEquals( - "usage: commandline [--config ] [-r ] [-a ] [-h] [-t] [-n] [-l"+EOL+ - " ] [-s ] [-v]"+EOL+ + "usage: commandline [-a ] [--config ] [-h] [-l ] [-n] [-r ]" + EOL + + " [-s ] [-t] [-v]" + EOL + "header"+EOL+ " -a,--age Age (in days) of cache item before being recomputed"+EOL+ " --config Use the specified configuration file"+EOL+ @@ -527,7 +527,7 @@ StringWriter out = new StringWriter(); formatter.printHelp(new PrintWriter(out),80, "foobar", "", options, 2, 2, "", true); assertEquals( - "usage: foobar [-a] [-c] [--bbb]"+SEP+ + "usage: foobar [-a] [--bbb] [-c]"+SEP+ " -a,--aaa aaaaaaa"+SEP+ " --bbb bbbbbbb"+SEP+ " -c ccccccc"+SEP Modified: jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java?view=diff&rev=544762&r1=544761&r2=544762 ============================================================================== --- jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java (original) +++ jakarta/commons/proper/cli/branches/cli-1.0.x/src/test/org/apache/commons/cli/TestHelpFormatter.java Wed Jun 6 01:01:19 2007 @@ -27,9 +27,13 @@ * * @author Slawek Zachcial * @author John Keyes ( john at integralsource.com ) + * @author brianegge **/ public class TestHelpFormatter extends TestCase { + + private static final String EOL = System.getProperty("line.separator"); + public static void main( String[] args ) { String[] testName = { TestHelpFormatter.class.getName() }; @@ -174,4 +178,23 @@ assertEquals("simple auto usage", expected, out.toString().trim()); out.reset(); } + + // This test ensures the options are properly sorted + // See https://issues.apache.org/jira/browse/CLI-131 + public void testPrintUsage() { + Option optionA = new Option("a", "first"); + Option optionB = new Option("b", "second"); + Option optionC = new Option("c", "third"); + Options opts = new Options(); + opts.addOption(optionA); + opts.addOption(optionB); + opts.addOption(optionC); + HelpFormatter helpFormatter = new HelpFormatter(); + ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); + PrintWriter printWriter = new PrintWriter(bytesOut); + helpFormatter.printUsage(printWriter, 80, "app", opts); + printWriter.close(); + assertEquals("usage: app [-a] [-b] [-c]" + EOL, bytesOut.toString()); + } + } --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org