Search in sources :

Example 1 with T2

use of org.osgl.Osgl.T2 in project actframework by actframework.

the class Help method showHelp.

public boolean showHelp(String command, CliContext context) {
    CliDispatcher dispatcher = context.app().cliDispatcher();
    CliHandler handler = dispatcher.handler(command);
    if (null == handler) {
        // context.println("Unrecongized command: %s", command);
        return false;
    }
    List<String> lines = new ArrayList<>();
    List<String> names = dispatcher.names(handler);
    T2<String, String> commandLine = handler.commandLine();
    lines.add("@|bold Usage|@: " + names.get(0));
    lines.add(commandLine._2);
    String summary = handler.summary();
    if (S.notBlank(summary)) {
        lines.add("");
        lines.add(summary);
    }
    List<T2<String, String>> options = handler.options();
    if (!options.isEmpty()) {
        lines.add("");
        lines.add("@|bold Options|@:");
        int maxLen = 0;
        for (T2<String, String> t2 : options) {
            maxLen = Math.max(maxLen, t2._1.length());
        }
        String fmt = "  %-" + (maxLen + 4) + "s %s";
        for (T2<String, String> t2 : options) {
            lines.add(S.fmt(fmt, t2._1, t2._2));
        }
    }
    if (names.size() > 1) {
        lines.add("");
        lines.add("@|Aliases|@: " + S.join(", ", C.list(names).tail()));
    }
    List<String> shortCuts = dispatcher.shortCuts(handler);
    if (shortCuts.size() > 0) {
        lines.add("");
        lines.add("@|bold Shortcuts|@: " + S.join(", ", shortCuts));
    }
    context.println(Ansi.ansi().render(S.join("\n", lines)).toString());
    return true;
}
Also used : CliDispatcher(act.cli.CliDispatcher) ArrayList(java.util.ArrayList) CliHandler(act.handler.CliHandler) T2(org.osgl.Osgl.T2)

Aggregations

CliDispatcher (act.cli.CliDispatcher)1 CliHandler (act.handler.CliHandler)1 ArrayList (java.util.ArrayList)1 T2 (org.osgl.Osgl.T2)1