use of act.handler.CliHandler in project actframework by actframework.
the class CliDispatcher method handler.
public CliHandler handler(String command) {
String command0 = command;
command = shortCuts.get(command);
if (null == command) {
command = command0;
}
CliHandler handler = registry.get(command);
if (null == handler && !command.startsWith("act.")) {
handler = registry.get("act." + command);
}
Act.Mode mode = Act.mode();
if (null != handler && handler.appliedIn(mode)) {
return handler;
}
return null;
}
use of act.handler.CliHandler 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;
}
Aggregations