ClientCommand command = commands.get(name);
data[i][0] = name;
data[i++][1] = command.getHelp();
}
TabularWriter tw = new TabularWriter(client.getPrintWriter(), "Command", "Description");
tw.setWidth(client.getConsoleWidth());
tw.setHideRowCount(true);
tw.print(data);
} else if ("api".equals(args[1])) {
Map<RhqManager, Object> services = client.getRemoteClient().getScriptingAPI();
if (args.length == 2) {
TabularWriter tw = new TabularWriter(client.getPrintWriter(), "API", "Package");
tw.setWidth(client.getConsoleWidth());
String[][] data = new String[services.size()][2];
int i = 0;
for (RhqManager api : services.keySet()) {
data[i][0] = api.name();
Object service = services.get(api);
data[i][1] = service.getClass().getInterfaces()[0].getPackage().getName();
i++;
}
tw.print(data);
} else if (args.length == 3) {
Object service = services.get(args[2]);
if (service != null) {
Class<?> intf = service.getClass().getInterfaces()[0];
Method[] methods = intf.getMethods();
Arrays.sort(methods, new Comparator<Method>() {
public int compare(Method o1, Method o2) {
return o1.getName().compareTo(o2.getName());
}
});
String[][] data = new String[methods.length][2];
for (int i = 0; i < methods.length; i++) {
Type returnType = methods[i].getGenericReturnType();
data[i][0] = ReflectionUtility.getSimpleTypeString(returnType);
Class<?>[] paramTypes = methods[i].getParameterTypes();
StringBuilder buf = new StringBuilder();
// buf.append(methods[i].getReturnType().getSimpleName());
// buf.append(" ");
buf.append(methods[i].getName());
buf.append("(");
Annotation[][] annotations = methods[i].getParameterAnnotations();
boolean secondary = false;
for (int j = 0; (j < paramTypes.length); ++j) {
String typeName = paramTypes[j].getSimpleName();
if (annotations != null && annotations.length >= i) {
Annotation[] as = annotations[j];
for (Annotation a : as) {
if (a instanceof WebParam) {
typeName += " " + ((WebParam) a).name();
}
}
}
if (secondary)
buf.append(", ");
secondary = true;
buf.append(typeName);
}
buf.append(")");
data[i][1] = buf.toString();
}
TabularWriter tw = new TabularWriter(client.getPrintWriter(), "Returns", "Signature");
tw.setWidth(client.getConsoleWidth());
tw.print(data);
} else {
client.getPrintWriter().println(
"Unknown service [" + args[2] + "] - try 'help api' for a listing of services");
}