protected StringBuffer renderOptions ( StringBuffer sb , int width , Options options , int leftPad , int descPad ) { final String lpad = createPadding ( leftPad ) ; final String dpad = createPadding ( descPad ) ; // first create list containing only <lpad>-a,--aaa where // -a is opt and --aaa is long opt; in parallel look for // the longest opt string this list will be then used to // sort options ascending int max = 0 ; List < StringBuffer > prefixList = new ArrayList < StringBuffer > ( ) ; List < Option > optList = options . helpOptions ( ) ; if ( getOptionComparator ( ) != null ) { Collections . sort ( optList , getOptionComparator ( ) ) ; } for ( Option option : optList ) { StringBuffer optBuf = new StringBuffer ( ) ; if ( option . getOpt ( ) == null ) { optBuf . append ( lpad ) . append ( " " ) . append ( getLongOptPrefix ( ) ) . append ( option . getLongOpt ( ) ) ; } else { optBuf . append ( lpad ) . append ( getOptPrefix ( ) ) . append ( option . getOpt ( ) ) ; if ( option . hasLongOpt ( ) ) { optBuf . append ( ' ' ) . append ( getLongOptPrefix ( ) ) . append ( option . getLongOpt ( ) ) ; } } if ( option . hasArg ( ) ) { String argName = option . getArgName ( ) ; if ( argName != null && argName . length ( ) == 0 ) { // if the option has a blank argname optBuf . append ( ' ' ) ; } else { optBuf . append ( option . hasLongOpt ( ) ? longOptSeparator : " " ) ; optBuf . append ( "<" ) . append ( argName != null ? option . getArgName ( ) : getArgName ( ) ) . append ( ">" ) ; } } prefixList . add ( optBuf ) ; max = optBuf . length ( ) > max ? optBuf . length ( ) : max ; } int x = 0 ; for ( Iterator < Option > it = optList . iterator ( ) ; it . hasNext ( ) ; ) { Option option = it . next ( ) ; StringBuilder optBuf = new StringBuilder ( prefixList . get ( x ++ ) . toString ( ) ) ; if ( optBuf . length ( ) < max ) { optBuf . append ( createPadding ( max - optBuf . length ( ) ) ) ; } optBuf . append ( dpad ) ; int nextLineTabStop = max + descPad ; if ( option . getDescription ( ) != null ) { optBuf . append ( option . getDescription ( ) ) ; } renderWrappedText ( sb , width , nextLineTabStop , optBuf . toString ( ) ) ; if ( it . hasNext ( ) ) { sb . append ( getNewLine ( ) ) ; } } return sb ; }
Render the specified Options and return the rendered Options in a StringBuffer .