1 50 package org.apache.avalon.excalibur.cli; 51 52 61 public final class CLUtil 62 { 63 private static final int MAX_DESCRIPTION_COLUMN_LENGTH = 60; 64 65 72 public static final StringBuffer describeOptions( final CLOptionDescriptor[] options ) 73 { 74 final String lSep = System.getProperty( "line.separator" ); 75 final StringBuffer sb = new StringBuffer (); 76 77 for( int i = 0; i < options.length; i++ ) 78 { 79 final char ch = (char)options[ i ].getId(); 80 final String name = options[ i ].getName(); 81 String description = options[ i ].getDescription(); 82 int flags = options[ i ].getFlags(); 83 boolean argumentRequired = 84 ( ( flags & CLOptionDescriptor.ARGUMENT_REQUIRED ) == 85 CLOptionDescriptor.ARGUMENT_REQUIRED ); 86 boolean twoArgumentsRequired = 87 ( ( flags & CLOptionDescriptor.ARGUMENTS_REQUIRED_2 ) == 88 CLOptionDescriptor.ARGUMENTS_REQUIRED_2 ); 89 boolean needComma = false; 90 if( twoArgumentsRequired ) 91 { 92 argumentRequired = true; 93 } 94 95 sb.append( '\t' ); 96 97 if( Character.isLetter( ch ) ) 98 { 99 sb.append( "-" ); 100 sb.append( ch ); 101 needComma = true; 102 } 103 104 if( null != name ) 105 { 106 if( needComma ) 107 { 108 sb.append( ", " ); 109 } 110 111 sb.append( "--" ); 112 sb.append( name ); 113 } 114 115 if( argumentRequired ) 116 { 117 sb.append( " <argument>" ); 118 } 119 if( twoArgumentsRequired ) 120 { 121 sb.append( "=<value>" ); 122 } 123 sb.append( lSep ); 124 125 if( null != description ) 126 { 127 while( description.length() > MAX_DESCRIPTION_COLUMN_LENGTH ) 128 { 129 final String descriptionPart = 130 description.substring( 0, MAX_DESCRIPTION_COLUMN_LENGTH ); 131 description = 132 description.substring( MAX_DESCRIPTION_COLUMN_LENGTH ); 133 sb.append( "\t\t" ); 134 sb.append( descriptionPart ); 135 sb.append( lSep ); 136 } 137 138 sb.append( "\t\t" ); 139 sb.append( description ); 140 sb.append( lSep ); 141 } 142 } 143 return sb; 144 } 145 146 150 private CLUtil() 151 { 152 } 153 } 154 | Popular Tags |