public String printHelp ( String commandName ) { int maxLength = 0 ; int width = 80 ; List < ProcessedOption > opts = getOptions ( ) ; for ( ProcessedOption o : opts ) { if ( o . getFormattedLength ( ) > maxLength ) maxLength = o . getFormattedLength ( ) ; } StringBuilder sb = new StringBuilder ( ) ; //first line sb . append ( "Usage: " ) ; if ( commandName == null || commandName . length ( ) == 0 ) sb . append ( name ( ) ) ; else sb . append ( commandName ) ; if ( opts . size ( ) > 0 ) sb . append ( " [<options>]" ) ; if ( argument != null ) { if ( argument . isTypeAssignableByResourcesOrFile ( ) ) sb . append ( " <file>" ) ; else sb . append ( " <" ) . append ( argument . getFieldName ( ) ) . append ( ">" ) ; } if ( arguments != null ) { if ( arguments . isTypeAssignableByResourcesOrFile ( ) ) sb . append ( " [<files>]" ) ; else sb . append ( " [<" ) . append ( arguments . getFieldName ( ) ) . append ( ">]" ) ; } sb . append ( Config . getLineSeparator ( ) ) ; //second line sb . append ( description ( ) ) . append ( Config . getLineSeparator ( ) ) ; //options and arguments if ( opts . size ( ) > 0 ) sb . append ( Config . getLineSeparator ( ) ) . append ( "Options:" ) . append ( Config . getLineSeparator ( ) ) ; for ( ProcessedOption o : opts ) sb . append ( o . getFormattedOption ( 2 , maxLength + 4 , width ) ) . append ( Config . getLineSeparator ( ) ) ; if ( arguments != null ) { sb . append ( Config . getLineSeparator ( ) ) . append ( "Arguments:" ) . append ( Config . getLineSeparator ( ) ) ; sb . append ( arguments . getFormattedOption ( 2 , maxLength + 4 , width ) ) . append ( Config . getLineSeparator ( ) ) ; } if ( argument != null ) { sb . append ( Config . getLineSeparator ( ) ) . append ( "Argument:" ) . append ( Config . getLineSeparator ( ) ) ; sb . append ( argument . getFormattedOption ( 2 , maxLength + 4 , width ) ) . append ( Config . getLineSeparator ( ) ) ; } return sb . toString ( ) ; }
Returns a description String based on the defined command and options . Useful when printing help info etc .