Search in sources :

Example 1 with Cmdlet

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;
    }
}
Also used : HongsException(io.github.ihongs.HongsException) Map(java.util.Map) HashMap(java.util.HashMap) DB(io.github.ihongs.db.DB) Cmdlet(io.github.ihongs.cmdlet.anno.Cmdlet)

Example 2 with Cmdlet

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);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Table(io.github.ihongs.db.Table) Matcher(java.util.regex.Matcher) Map(java.util.Map) DB(io.github.ihongs.db.DB) Cmdlet(io.github.ihongs.cmdlet.anno.Cmdlet)

Example 3 with Cmdlet

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);
    }
}
Also used : PrintStream(java.io.PrintStream) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Cmdlet(io.github.ihongs.cmdlet.anno.Cmdlet)

Example 4 with Cmdlet

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);
    }
}
Also used : PrintStream(java.io.PrintStream) MalformedURLException(java.net.MalformedURLException) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) HongsException(io.github.ihongs.HongsException) BufferedReader(java.io.BufferedReader) HashMap(java.util.HashMap) Map(java.util.Map) PrintWriter(java.io.PrintWriter) Cmdlet(io.github.ihongs.cmdlet.anno.Cmdlet)

Example 5 with Cmdlet

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);
    }
}
Also used : PrintStream(java.io.PrintStream) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Mathod(io.github.ihongs.CoreRoster.Mathod) Cmdlet(io.github.ihongs.cmdlet.anno.Cmdlet)

Aggregations

Cmdlet (io.github.ihongs.cmdlet.anno.Cmdlet)18 Map (java.util.Map)12 HongsException (io.github.ihongs.HongsException)8 PrintStream (java.io.PrintStream)8 HashMap (java.util.HashMap)7 IOException (java.io.IOException)4 TreeMap (java.util.TreeMap)4 PrintWriter (java.io.PrintWriter)3 DB (io.github.ihongs.db.DB)2 BufferedReader (java.io.BufferedReader)2 File (java.io.File)2 InputStreamReader (java.io.InputStreamReader)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Method (java.lang.reflect.Method)2 HttpURLConnection (java.net.HttpURLConnection)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Core (io.github.ihongs.Core)1 CoreConfig (io.github.ihongs.CoreConfig)1 Mathod (io.github.ihongs.CoreRoster.Mathod)1