1 17 package org.apache.commons.cli.avalon; 18 20 26 public final class CLUtil 27 { 28 private static final int MAX_DESCRIPTION_COLUMN_LENGTH = 60; 29 30 37 public static final StringBuffer describeOptions( final CLOptionDescriptor[] options ) 38 { 39 final String lSep = System.getProperty( "line.separator" ); 40 final StringBuffer sb = new StringBuffer (); 41 42 for( int i = 0; i < options.length; i++ ) 43 { 44 final char ch = (char)options[i].getId(); 45 final String name = options[i].getName(); 46 String description = options[i].getDescription(); 47 int flags = options[i].getFlags(); 48 boolean argumentRequired = 49 ((flags & CLOptionDescriptor.ARGUMENT_REQUIRED) == 50 CLOptionDescriptor.ARGUMENT_REQUIRED); 51 boolean twoArgumentsRequired = 52 ((flags & CLOptionDescriptor.ARGUMENTS_REQUIRED_2) == 53 CLOptionDescriptor.ARGUMENTS_REQUIRED_2); 54 boolean needComma = false; 55 if( twoArgumentsRequired ) 56 { 57 argumentRequired = true; 58 } 59 60 sb.append( '\t' ); 61 62 if( Character.isLetter( ch ) ) 63 { 64 sb.append( "-" ); 65 sb.append( ch ); 66 needComma = true; 67 } 68 69 if( null != name ) 70 { 71 if( needComma ) 72 { 73 sb.append( ", " ); 74 } 75 76 sb.append( "--" ); 77 sb.append( name ); 78 } 79 80 if( argumentRequired ) 81 { 82 sb.append( " <argument>" ); 83 } 84 if( twoArgumentsRequired ) 85 { 86 sb.append( "=<value>" ); 87 } 88 sb.append( lSep ); 89 90 if( null != description ) 91 { 92 while( description.length() > MAX_DESCRIPTION_COLUMN_LENGTH ) 93 { 94 final String descriptionPart = 95 description.substring( 0, MAX_DESCRIPTION_COLUMN_LENGTH ); 96 description = 97 description.substring( MAX_DESCRIPTION_COLUMN_LENGTH ); 98 sb.append( "\t\t" ); 99 sb.append( descriptionPart ); 100 sb.append( lSep ); 101 } 102 103 sb.append( "\t\t" ); 104 sb.append( description ); 105 sb.append( lSep ); 106 } 107 } 108 return sb; 109 } 110 111 115 private CLUtil() 116 { 117 } 118 } 119 | Popular Tags |