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 2003/02/21 01:17:27 UTC

DO NOT REPLY [Bug 17268] New: - Problem in printUsage for OptionGroup

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17268>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=17268

Problem in printUsage for OptionGroup

           Summary: Problem in printUsage for OptionGroup
           Product: Commons
           Version: 1.0 Beta 2
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Minor
          Priority: Other
         Component: CLI
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: mlanzetta@accelrys.com


The printUsage method, when used with an OptionGroup in the Options, will print 
every option in that group past the first more than once (once as a group 
option, and once as a non-group option).  This is due to a bug in the logic of 
printUsage, at line 267.  Alteration required:




// if the Option is not part of an OptionGroup


else {




change to:




// if the Option is not part of an OptionGroup


else if (group == null) {






I've built a unit test for this:




	public void testMultiOptionPrintUsage() throws Exception


	{


		String firstOption = "FirstOption";


		String secondOption = "SecondOption";




		Options options = new Options();


		OptionGroup optGroup = new OptionGroup();


		optGroup.addOption(OptionBuilder.create(firstOption));


		optGroup.addOption(OptionBuilder.create(secondOption));


		options.addOptionGroup(optGroup);


		


		ByteArrayOutputStream byteStream = new ByteArrayOutputStream();


		HelpFormatter help = new HelpFormatter();


		help.printUsage(new PrintWriter(byteStream, true), 80, "Test", options);


		


		String usageString = byteStream.toString();


		assertTrue("Should not find multiple copies of "+firstOption, 
usageString.indexOf(firstOption, 
usageString.indexOf(firstOption)+firstOption.length()) == -1);


		assertTrue("Should not find multiple copies of "+secondOption, 
usageString.indexOf(secondOption, 
usageString.indexOf(secondOption)+secondOption.length()) == -1);


	}

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org