Skip to content

Commit a021283

Browse files
author
John Keyes
committed
some fixes for autousage and padding
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/cli/trunk@129821 13f79535-47bb-0310-9956-ffa450edef68
1 parent 872f1d5 commit a021283

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/java/org/apache/commons/cli/HelpFormatter.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class HelpFormatter
7979
{
8080
// --------------------------------------------------------------- Constants
8181

82-
public static final int DEFAULT_WIDTH = 80;
82+
public static final int DEFAULT_WIDTH = 74;
8383
public static final int DEFAULT_LEFT_PAD = 1;
8484
public static final int DEFAULT_DESC_PAD = 3;
8585
public static final String DEFAULT_SYNTAX_PREFIX = "usage: ";
@@ -277,10 +277,7 @@ public void printUsage( PrintWriter pw, int width, String app, Options options )
277277
buff.append( "--" ).append( option.getLongOpt() );
278278
}
279279

280-
if( option.getValueSeparator() != (char)0 ) {
281-
buff.append( option.getValueSeparator() );
282-
}
283-
else if( option.hasArg() ){
280+
if( option.hasArg() ){
284281
buff.append( " " );
285282
}
286283

@@ -347,7 +344,7 @@ protected StringBuffer renderOptions( StringBuffer sb,
347344
List prefixList = new ArrayList();
348345
Option option;
349346
List optList = options.helpOptions();
350-
Collections.sort( optList, new StringBufferComparator() );
347+
Collections.sort( optList, new StringBufferComparator() );
351348
for ( Iterator i = optList.iterator(); i.hasNext(); )
352349
{
353350
option = (Option) i.next();
@@ -369,7 +366,7 @@ protected StringBuffer renderOptions( StringBuffer sb,
369366

370367
if( option.hasArg() ) {
371368
if( option.hasArgName() ) {
372-
optBuf.append( option.getArgName() );
369+
optBuf.append(" <").append( option.getArgName() ).append( '>' );
373370
}
374371
else {
375372
optBuf.append(' ');
@@ -378,12 +375,18 @@ protected StringBuffer renderOptions( StringBuffer sb,
378375

379376
prefixList.add(optBuf);
380377
max = optBuf.length() > max ? optBuf.length() : max;
378+
}
379+
int x = 0;
380+
for ( Iterator i = optList.iterator(); i.hasNext(); )
381+
{
382+
option = (Option) i.next();
383+
optBuf = new StringBuffer( prefixList.get( x++ ).toString() );
381384

382385
if ( optBuf.length() < max )
383386
{
384-
optBuf.append(createPadding(max-optBuf.length()));
387+
optBuf.append(createPadding(max - optBuf.length()));
385388
}
386-
optBuf.append(dpad);
389+
optBuf.append( dpad );
387390

388391
int nextLineTabStop = max + descPad;
389392
renderWrappedText(sb, width, nextLineTabStop,

0 commit comments

Comments
 (0)