Option optionAnn = null; Boolean required = null; Description description = new Description(ab); Annotation info = null; for (Annotation parameterAnnotation : ab) { description = new Description(description, new Description(a));
public void printDescriptionSection(CommandDescriptor<?> command, Appendable stream) throws IOException { String man = command.getDescription().getMan(); if (man.length() > 0) { stream.append("DESCRIPTION\n"); Util.indent(Util.MAN_TAB, man, stream); stream.append("\n\n"); } }
/** * Returns the command usage, shortcut for invoking <code>getDescription().getUsage()</code> on this * object. * * @return the command usage */ public final String getUsage() { return description != null ? description.getUsage() : ""; }
public void testClassDescription() throws Exception { @Usage("class_usage") @Man("class_man") class A { } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); assertEquals("class_usage", c.getUsage()); assertEquals("class_usage", c.getDescription().getUsage()); assertEquals("class_man", c.getDescription().getMan()); }
String man = getDescription().getMan(); if (man.length() > 0) { writer.append("DESCRIPTION\n"); writer.append(Util.MAN_TAB); option.printUsage(writer); String optionText = option.getDescription().getBestEffortMan(); if (optionText.length() > 0) { writer.append("\n"); for (CommandDescriptor<T> method : methods.values()) { writer.append(Util.MAN_TAB).append(method.getName()); String methodText = method.getDescription().getBestEffortMan(); if (methodText.length() > 0) { writer.append("\n"); String man = getDescription().getMan(); if (man.length() > 0) { writer.append("DESCRIPTION\n"); writer.append(Util.MAN_TAB); parameter.printUsage(writer); String parameterText = parameter.getDescription().getBestEffortMan(); if (parameterText.length() > 0) { writer.append("\n");
protected boolean printParameter(boolean printed, ParameterDescriptor parameter, Appendable stream) throws IOException { if (!printed) { stream.append("PARAMETERS\n"); } stream.append(Util.MAN_TAB); parameter.printUsage(stream); String parameterText = parameter.getDescription().getBestEffortMan(); if (parameterText.length() > 0) { stream.append("\n"); Util.indent(Util.MAN_TAB_EXTRA, parameterText, stream); } stream.append("\n\n"); return true; } }
public void testMethodDescription() throws Exception { class A { @Usage("method_usage") @Man("method_man") @Command void m() {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); CommandDescriptor<Instance<A>> m = c.getSubordinate("m"); assertEquals("method_usage", m.getUsage()); assertEquals("method_usage", m.getDescription().getUsage()); assertEquals("method_man", m.getDescription().getMan()); }
protected void printSubordinates(CommandDescriptor<?> command, Appendable stream) throws IOException { for (CommandDescriptor<?> subordinate : command.getSubordinates().values()) { stream.append(Util.MAN_TAB).append(subordinate.getName()); String methodText = subordinate.getDescription().getBestEffortMan(); if (methodText.length() > 0) { stream.append("\n"); Util.indent(Util.MAN_TAB_EXTRA, methodText, stream); } stream.append("\n\n"); } }
descriptor = new CommandDescriptor<Object>(name, new Description()) { @Override public CommandDescriptor<Object> getOwner() {
public void testParameterMetaDescription1() throws Exception { class A { @Command void m(@Foo String s) {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); CommandDescriptor<Instance<A>> m = c.getSubordinate("m"); OptionDescriptor a = m.getOption("-a"); assertEquals("foo_usage", a.getUsage()); assertEquals("foo_usage", a.getDescription().getUsage()); assertEquals("foo_man", a.getDescription().getMan()); }
public final String getUsage() { return description != null ? description.getUsage() : ""; }
public void printDescriptionSection(CommandDescriptor<?> command, Appendable stream) throws IOException { String man = command.getDescription().getMan(); if (man.length() > 0) { stream.append("DESCRIPTION\n"); Util.indent(Util.MAN_TAB, man, stream); stream.append("\n\n"); } }
protected boolean printParameter(boolean printed, ParameterDescriptor parameter, Appendable stream) throws IOException { if (!printed) { stream.append("PARAMETERS\n"); } stream.append(Util.MAN_TAB); parameter.printUsage(stream); String parameterText = parameter.getDescription().getBestEffortMan(); if (parameterText.length() > 0) { stream.append("\n"); Util.indent(Util.MAN_TAB_EXTRA, parameterText, stream); } stream.append("\n\n"); return true; } }
} else { Map<String, MethodDescriptor<T>> methodMap = new LinkedHashMap<String, MethodDescriptor<T>>(); ClassDescriptor<T> classDescriptor = new ClassDescriptor<T>(type, commandName, methodMap, new Description(type)); for (Method method : methods) { String methodName;
public void testParameterMetaDescription3() throws Exception { class A { @Command void m( @Usage("option_usage") @Foo String s) {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); CommandDescriptor<Instance<A>> m = c.getSubordinate("m"); OptionDescriptor a = m.getOption("-a"); assertEquals("option_usage", a.getUsage()); assertEquals("option_usage", a.getDescription().getUsage()); assertEquals("foo_man", a.getDescription().getMan()); } }
/** * Returns the command usage, shortcut for invoking <code>getDescription().getUsage()</code> on this * object. * * @return the command usage */ public final String getUsage() { return description != null ? description.getUsage() : ""; } }
protected void printSubordinates(CommandDescriptor<?> command, Appendable stream) throws IOException { for (CommandDescriptor<?> subordinate : command.getSubordinates().values()) { stream.append(Util.MAN_TAB).append(subordinate.getName()); String methodText = subordinate.getDescription().getBestEffortMan(); if (methodText.length() > 0) { stream.append("\n"); Util.indent(Util.MAN_TAB_EXTRA, methodText, stream); } stream.append("\n\n"); } }
private <T> MethodDescriptor<T> create(ClassDescriptor<T> classDescriptor, String name, Method method) throws IntrospectionException { Description info = new Description(method); MethodDescriptor<T> methodDescriptor = new MethodDescriptor<T>( classDescriptor, method, name, info); Type[] parameterTypes = method.getGenericParameterTypes(); Annotation[][] parameterAnnotationMatrix = method.getParameterAnnotations(); for (int i = 0;i < parameterAnnotationMatrix.length;i++) { Annotation[] parameterAnnotations = parameterAnnotationMatrix[i]; Type parameterType = parameterTypes[i]; Tuple tuple = get(parameterAnnotations); MethodArgumentBinding binding = new MethodArgumentBinding(i); ParameterDescriptor parameter = create( binding, parameterType, tuple.argumentAnn, tuple.optionAnn, tuple.required, tuple.descriptionAnn, tuple.ann); if (parameter != null) { methodDescriptor.addParameter(parameter); } else { log.log(Level.FINE, "Method argument with index " + i + " of method " + method + " is not annotated"); } } return methodDescriptor; }
public void testParameterDescription() throws Exception { class A { @Command void m( @Usage("option_usage") @Man("option_man") @Option(names = "a") String s) {} } CommandDescriptor<Instance<A>> c = CommandFactory.DEFAULT.create(A.class); CommandDescriptor<Instance<A>> m = c.getSubordinate("m"); OptionDescriptor a = m.getOption("-a"); assertEquals("option_usage", a.getUsage()); assertEquals("option_usage", a.getDescription().getUsage()); assertEquals("option_man", a.getDescription().getMan()); }
/** * Returns the command usage, shortcut for invoking <code>getDescription().getUsage()</code> on this * object. * * @return the command usage */ public final String getUsage() { return description != null ? description.getUsage() : ""; }