use of act.handler.CliHandler in project actframework by actframework.
the class Help method list.
private void list(String search, String label, String fmt, List<String> commands, CliDispatcher dispatcher, CliContext context) {
List<String> lines = new ArrayList<>();
boolean noSearch = S.blank(search);
if (noSearch) {
lines.add(label.toUpperCase());
lines.add("");
}
for (String cmd : commands) {
CliHandler handler = dispatcher.handler(cmd);
T2<String, String> commandLine = handler.commandLine();
if (noSearch || commandLine._1.contains(search)) {
lines.add(S.fmt(fmt, cmd, commandLine._2));
}
}
context.println(Ansi.ansi().render(S.join("\n", lines)).toString());
}
use of act.handler.CliHandler in project actframework by actframework.
the class CliDispatcher method commands.
/**
* Returns all commands in alphabetic order
*
* @return the list of commands
*/
public List<String> commands(boolean sys, boolean app) {
C.List<String> list = C.newList();
Act.Mode mode = Act.mode();
boolean all = !sys && !app;
for (String s : registry.keySet()) {
boolean isSysCmd = s.startsWith("act.");
if (isSysCmd && !sys && !all) {
continue;
}
if (!isSysCmd && !app && !all) {
continue;
}
CliHandler h = registry.get(s);
if (h.appliedIn(mode)) {
list.add(s);
}
}
return list.sorted(new Osgl.Comparator<String>() {
@Override
public int compare(String o1, String o2) {
boolean b1 = (o1.startsWith("act."));
boolean b2 = (o2.startsWith("act."));
if (b1 & !b2) {
return -1;
}
if (!b1 & b2) {
return 1;
}
return o1.compareTo(o2);
}
});
}
use of act.handler.CliHandler in project actframework by actframework.
the class CommanderByteCodeScannerTest method instanceWithReturnValue.
@Test
public void instanceWithReturnValue() {
scan(InstanceWithReturnType.class);
CliHandler handler = dispatcher.handler("user.list");
assertNotNull(handler);
CommanderClassMetaInfo classMetaInfo = infoSrc.commanderMetaInfo(InstanceWithReturnType.class.getName());
CommandMethodMetaInfo methodMetaInfo = classMetaInfo.command("user.list");
eq("getUserList", methodMetaInfo.methodName());
eq(InstanceWithReturnType.class.getName() + ".getUserList", methodMetaInfo.fullName());
no(methodMetaInfo.isStatic());
PropertySpec.MetaInfo dataView = methodMetaInfo.propertySpec();
ceq(C.list("fn", "ln"), dataView.outputFields());
eq(Type.getType(List.class), methodMetaInfo.returnType());
C.List<CommandParamMetaInfo> params = methodMetaInfo.params();
eq(4, params.size());
CommandParamMetaInfo op = params.get(0);
eq("id", op.name());
ParamOptionAnnoInfo anno = op.optionInfo();
eq("-i", anno.lead1());
eq("--id", anno.lead2());
eq("group1", anno.group());
assertNull(anno.defVal());
op = params.get(1);
eq("b", op.name());
assertNull(op.optionInfo());
op = params.get(2);
eq("limit", op.name());
anno = op.optionInfo();
eq("-l", anno.lead1());
eq("--limit", anno.lead2());
assertNull(anno.group());
eq("-1", anno.defVal());
op = params.get(3);
eq("l", op.name());
assertNull(op.optionInfo());
}
use of act.handler.CliHandler in project actframework by actframework.
the class CliOverHttp method handler.
private CliHandler handler(String cmd) {
CliHandler handler = dispatcher.handler(cmd);
notFoundIfNull(handler);
return handler;
}
use of act.handler.CliHandler in project actframework by actframework.
the class CliOverHttp method run.
@PostAction("cmd")
public Result run(String cmd, ActionContext context) throws IOException {
CliHandler handler = handler(cmd);
ByteArrayOutputStream os = new ByteArrayOutputStream();
CliContext cliContext = new CliOverHttpContext(context, os);
handler.handle(cliContext);
cliContext.flush();
String txt = new String(os.toByteArray(), "UTF-8");
txt = txt.replace("^J", "\n");
return text(txt);
}
Aggregations