Search in sources :

Example 1 with MarkdownFormatter

use of aQute.lib.markdown.MarkdownFormatter in project bnd by bndtools.

the class CommandLine method generateDocumentation.

public void generateDocumentation(Object target, Appendable out) {
    MarkdownFormatter f = new MarkdownFormatter(out);
    f.h1("Available Commands:");
    Map<String, Method> commands = getCommands(target);
    for (String command : commands.keySet()) {
        Class<? extends Options> specification = (Class<? extends Options>) commands.get(command).getParameterTypes()[0];
        Map<String, Method> options = getOptions(specification);
        Arguments patterns = specification.getAnnotation(Arguments.class);
        f.h2(command);
        Description descr = specification.getAnnotation(Description.class);
        if (descr != null) {
            f.format("%s%n%n", descr.value());
        }
        f.h3("Synopsis:");
        f.code(getSynopsis(command, options, patterns));
        if (!options.isEmpty()) {
            f.h3("Options:");
            for (Entry<String, Method> entry : options.entrySet()) {
                Option option = getOption(entry.getKey(), entry.getValue());
                //
                f.inlineCode(//
                "%s -%s --%s %s%s", //
                option.required ? " " : "[", //
                option.shortcut, //
                option.name, //
                option.paramType, option.required ? " " : "]");
                if (option.description != null) {
                    f.format("%s", option.description);
                    f.endP();
                }
            }
            f.format("%n");
        }
    }
    f.flush();
}
Also used : Method(java.lang.reflect.Method) MarkdownFormatter(aQute.lib.markdown.MarkdownFormatter)

Aggregations

MarkdownFormatter (aQute.lib.markdown.MarkdownFormatter)1 Method (java.lang.reflect.Method)1