@@ -269,11 +269,24 @@ public void printUsage( PrintWriter pw, int width, String app, Options options )
269269 if ( !option .isRequired () ) {
270270 buff .append ( "[" );
271271 }
272- buff .append ( "-" ).append ( option .getOpt () );
272+
273+ if ( !" " .equals ( option .getOpt () ) ) {
274+ buff .append ( "-" ).append ( option .getOpt () );
275+ }
276+ else {
277+ buff .append ( "--" ).append ( option .getLongOpt () );
278+ }
279+
280+ if ( option .getValueSeparator () != (char )0 ) {
281+ buff .append ( option .getValueSeparator () );
282+ }
283+ else if ( option .hasArg () ){
284+ buff .append ( " " );
285+ }
273286
274287 // if the Option has a value
275288 if ( option .hasArg () ) {
276- buff .append ( " arg" );
289+ buff .append ( option . getArgName () );
277290 }
278291
279292 // if the Option is not a required option
@@ -284,7 +297,6 @@ public void printUsage( PrintWriter pw, int width, String app, Options options )
284297 }
285298 }
286299
287- System .out .println ( "->" + buff .toString () );
288300 // call printWrapped
289301 printWrapped ( pw , width , buff .toString ().indexOf (' ' )+1 ,
290302 buff .toString () );
@@ -334,7 +346,9 @@ protected StringBuffer renderOptions( StringBuffer sb,
334346 StringBuffer optBuf ;
335347 List prefixList = new ArrayList ();
336348 Option option ;
337- for ( Iterator i = options .getOptions ().iterator (); i .hasNext (); )
349+ List optList = options .helpOptions ();
350+ Collections .sort ( optList , new StringBufferComparator () );
351+ for ( Iterator i = optList .iterator (); i .hasNext (); )
338352 {
339353 option = (Option ) i .next ();
340354 optBuf = new StringBuffer (8 );
@@ -353,49 +367,30 @@ protected StringBuffer renderOptions( StringBuffer sb,
353367
354368 }
355369
356-
357- if ( option .hasArg () )
358- {
359- //FIXME - should have a way to specify arg name per option
360- optBuf .append (' ' ).append (defaultArgName );
370+ if ( option .hasArg () ) {
371+ if ( option .hasArgName () ) {
372+ optBuf .append ( option .getArgName () );
373+ }
374+ else {
375+ optBuf .append (' ' );
376+ }
361377 }
378+
362379 prefixList .add (optBuf );
363380 max = optBuf .length () > max ? optBuf .length () : max ;
364- }
365381
366- //right pad the prefixes
367- for ( Iterator i = prefixList .iterator (); i .hasNext (); )
368- {
369- optBuf = (StringBuffer ) i .next ();
370382 if ( optBuf .length () < max )
371383 {
372- optBuf .append (createPadding (max -optBuf .length ()));
384+ optBuf .append (createPadding (max -optBuf .length ()));
373385 }
374386 optBuf .append (dpad );
375- }
376-
377- //sort this list ascending
378- Collections .sort (prefixList , new StringBufferComparator ());
379-
380- //finally render options
381- int nextLineTabStop = max + descPad ;
382- String opt ;
383- int optOffset = leftPad + defaultOptPrefix .length ();
384-
385- for ( Iterator i = prefixList .iterator (); i .hasNext (); )
386- {
387- optBuf = (StringBuffer ) i .next ();
388- opt = optBuf .toString ().trim ();
389- if ( opt .indexOf ( ',' ) != -1 ) {
390- opt = opt .substring (0 , opt .indexOf ( ',' , optOffset ) );
391- }
392- option = options .getOption (opt );
393-
387+
388+ int nextLineTabStop = max + descPad ;
394389 renderWrappedText (sb , width , nextLineTabStop ,
395390 optBuf .append (option .getDescription ()).toString ());
396391 if ( i .hasNext () )
397392 {
398- sb .append (defaultNewLine );
393+ sb .append (defaultNewLine );
399394 }
400395 }
401396
0 commit comments