1 8 package org.jboss.axis.utils; 11 12 13 19 public final class CLUtil 20 { 21 private static final int MAX_DESCRIPTION_COLUMN_LENGTH = 60; 22 23 30 public static final StringBuffer describeOptions(final CLOptionDescriptor[] options) 31 { 32 final StringBuffer sb = new StringBuffer (); 33 34 for (int i = 0; i < options.length; i++) 35 { 36 final char ch = (char)options[i].getId(); 37 final String name = options[i].getName(); 38 String description = options[i].getDescription(); 39 int flags = options[i].getFlags(); 40 boolean argumentRequired = 41 ((flags & CLOptionDescriptor.ARGUMENT_REQUIRED) == 42 CLOptionDescriptor.ARGUMENT_REQUIRED); 43 boolean twoArgumentsRequired = 44 ((flags & CLOptionDescriptor.ARGUMENTS_REQUIRED_2) == 45 CLOptionDescriptor.ARGUMENTS_REQUIRED_2); 46 boolean needComma = false; 47 if (twoArgumentsRequired) 48 argumentRequired = true; 49 50 sb.append('\t'); 51 52 if (Character.isLetter(ch)) 53 { 54 sb.append("-"); 55 sb.append(ch); 56 needComma = true; 57 } 58 59 if (null != name) 60 { 61 if (needComma) 62 { 63 sb.append(", "); 64 } 65 66 sb.append("--"); 67 sb.append(name); 68 if (argumentRequired) 69 { 70 sb.append(" <argument>"); 71 } 72 if (twoArgumentsRequired) 73 { 74 sb.append("=<value>"); 75 } 76 sb.append(JavaUtils.LS); 77 } 78 79 if (null != description) 80 { 81 while (description.length() > MAX_DESCRIPTION_COLUMN_LENGTH) 82 { 83 final String descriptionPart = 84 description.substring(0, MAX_DESCRIPTION_COLUMN_LENGTH); 85 description = 86 description.substring(MAX_DESCRIPTION_COLUMN_LENGTH); 87 sb.append("\t\t"); 88 sb.append(descriptionPart); 89 sb.append(JavaUtils.LS); 90 } 91 92 sb.append("\t\t"); 93 sb.append(description); 94 sb.append(JavaUtils.LS); 95 } 96 } 97 return sb; 98 } 99 100 103 private CLUtil() 104 { 105 } 106 } 107 | Popular Tags |