use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Common method showCmdlets.
@Cmdlet("show-cmdlets")
public static void showCmdlets(String[] args) {
Map<String, String> a = new TreeMap(new PathComparator('.'));
int i = 0, j;
for (Map.Entry<String, Method> et : CmdletRunner.getCmdlets().entrySet()) {
String k = et.getKey();
Method v = et.getValue();
a.put(k, v.getDeclaringClass().getName() + "." + v.getName());
j = k.length();
if (i < j && j < 39) {
i = j;
}
}
PrintStream out = CmdletHelper.OUT.get();
for (Map.Entry<String, String> n : a.entrySet()) {
StringBuilder s = new StringBuilder();
s.append(n.getKey());
for (j = n.getKey().length(); j < i; j++) {
s.append(" ");
}
s.append("\t");
s.append(n.getValue());
out.println(s);
}
}
use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class LuceneCmdlet method search.
@Cmdlet("search")
public static void search(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, new String[] { "conf=s", "form=s", "id*s", "wd*s", "rb*s", "ob*s", "pn:i", "gn:i", "rn:i" });
String conf = Synt.asString(opts.remove("conf"));
String name = Synt.asString(opts.remove("name"));
LuceneRecord so = LuceneRecord.getInstance(conf, name);
Map rsp = so.search(opts);
CmdletHelper.preview(rsp);
}
use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class LuceneCmdlet method update.
@Cmdlet("update")
public static void update(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, new String[] { "conf=s", "form=s", "id*s", "!A" });
args = (String[]) opts.get("");
String conf = Synt.asString(opts.remove("conf"));
String name = Synt.asString(opts.remove("name"));
List<String> ds = Synt.asList(opts.remove("id"));
LuceneRecord so = LuceneRecord.getInstance(conf, name);
Map rd = data(args[0]);
try {
so.begin();
for (String id : ds) {
so.put(id, rd);
}
so.commit();
} catch (HongsException ex) {
so.revert();
throw ex;
} finally {
so.close();
}
}
use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class CoreRoster method addCmds.
private static void addCmds(Map<String, Method> acts, Cmdlet anno, String clsn, Class clso) {
String actn = anno.value();
if (actn == null || actn.length() == 0) {
actn = clsn;
}
Method[] mtds = clso.getMethods();
for (Method mtdo : mtds) {
String mtdn = mtdo.getName();
// 从注解提取动作名
Cmdlet annx = (Cmdlet) mtdo.getAnnotation(Cmdlet.class);
if (annx == null) {
continue;
}
String actx = annx.value();
if (actx == null || actx.length() == 0) {
actx = mtdn;
}
// 检查方法是否合法
Class[] prms = mtdo.getParameterTypes();
if (prms == null || prms.length != 1 || !String[].class.isAssignableFrom(prms[0])) {
throw new HongsExemption(832, "Can not find cmdlet method '" + clsn + "." + mtdn + "(String[])'.");
}
if ("__main__".equals(actx)) {
acts.put(actn, /*__main__*/
mtdo);
} else {
acts.put(actn + "." + actx, mtdo);
}
}
}
use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class LuceneCmdlet method delete.
@Cmdlet("delete")
public static void delete(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, new String[] { "conf=s", "form=s", "id*s" });
String conf = Synt.asString(opts.remove("conf"));
String name = Synt.asString(opts.remove("name"));
List<String> ds = Synt.asList(opts.remove("id"));
LuceneRecord so = LuceneRecord.getInstance(conf, name);
try {
so.begin();
for (String id : ds) {
so.del(id);
}
so.commit();
} catch (HongsException ex) {
so.revert();
throw ex;
} finally {
so.close();
}
}
Aggregations