use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class UserCmdlet method uproot.
/**
* 归并命令
* @param args
* @throws HongsException
*/
@Cmdlet("uproot")
public static void uproot(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, "uid=s", "uids=s", "!A", "!U", "?Usage: attach --uid UID --uids UID1,UID2...");
String uid = (String) opts.get("uid");
String uidz = (String) opts.get("uids");
Set<String> uids = Synt.toSet(uidz);
DB db = DB.getInstance("master");
try {
db.begin();
uproot(uid, uids);
db.commit();
} catch (HongsException ex) {
db.revert();
throw ex;
}
}
use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Cmdrun method exec.
@Cmdlet("__main__")
public static void exec(String[] args) throws HongsException {
Map opts = CmdletHelper.getOpts(args, "from=s", "to=s", "sync:b", "del-tables:b", "del-fields:b");
String fr = (String) opts.get("from");
String to = (String) opts.get("to");
boolean sc = (boolean) opts.get("sync");
boolean dt = (boolean) opts.get("del-tables");
boolean df = (boolean) opts.get("del-fields");
Pattern patt = Pattern.compile("\\.\\w+$");
Matcher frMt = patt.matcher(fr);
Matcher toMt = patt.matcher(to);
if (frMt.find() && toMt.find()) {
DB frDb = DB.getInstance(fr.substring(0, frMt.start()));
Table frTb = frDb.getTable(fr.substring(frMt.start() + 1));
DB toDb = DB.getInstance(to.substring(0, toMt.start()));
Table toTb = toDb.getTable(to.substring(toMt.start() + 1));
if (sc) {
new TableDeff(frTb).syncSlaver(toTb, df);
} else {
new TableDeff(frTb).deffSlaver(toTb, df);
}
} else {
DB frDb = DB.getInstance(fr);
DB toDb = DB.getInstance(fr);
if (sc) {
new DBDeff(frDb).syncSlaver(toDb, null, null, dt, df);
} else {
new DBDeff(frDb).deffSlaver(toDb, null, null, dt, df);
}
}
}
use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Common method showProperties.
@Cmdlet("show-properties")
public static void showProperties(String[] args) {
Map<String, String> a = new TreeMap(new PropComparator());
Map<String, String> m = new HashMap(System.getProperties());
int i = 0, j;
for (Map.Entry<String, String> et : m.entrySet()) {
String k = et.getKey();
String v = et.getValue();
a.put(k, v);
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 Access method exec.
@Cmdlet("exec")
public static void exec(String[] args) throws HongsException {
if (args.length == 0) {
CmdletHelper.ERR.get().println("Usage: CMDLET_NAME [ARG_0] [ARG_1] ...");
return;
}
// 请求参数
Map rep = new HashMap();
rep.put("cmd", args[0]);
if (args.length > 1) {
rep.put("args", Arrays.copyOfRange(args, 1, args.length));
}
String req = Dawn.toString(rep, true);
// 命令接口
String url = Core.SERV_HREF + Core.SERV_PATH + "/common/more/exec" + Cnst.ACT_EXT;
try {
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setConnectTimeout(0);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json,text/html,*/*;q=0.8");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("X-Requested-With", CoreConfig.getInstance().getProperty("core.powered.by"));
String ln;
PrintStream ps;
PrintWriter pw;
BufferedReader br;
pw = new PrintWriter(conn.getOutputStream());
pw.print(req);
pw.flush();
pw.close();
br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
ps = CmdletHelper.OUT.get();
while ((ln = br.readLine()) != null) {
ps.print(ln);
}
ps.println();
} catch (UnsupportedEncodingException ex) {
throw new HongsException(1111, ex);
} catch (MalformedURLException ex) {
throw new HongsException(1111, ex);
} catch (IOException ex) {
throw new HongsException(1110, ex);
}
}
use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.
the class Common method showActions.
@Cmdlet("show-actions")
public static void showActions(String[] args) {
Map<String, String> a = new TreeMap(new PathComparator('/'));
int i = 0, j;
for (Map.Entry<String, Mathod> et : ActionRunner.getActions().entrySet()) {
String k = et.getKey();
Mathod v = et.getValue();
a.put(k, v.toString());
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);
}
}
Aggregations