Search in sources :

Example 16 with Cmdlet

use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.

the class CoreRoster method addServ.

private static void addServ(Map<String, Mathod> acts, Map<String, Method> cmds, String... pkgs) {
    for (String pkgn : pkgs) {
        pkgn = pkgn.trim();
        if (pkgn.length() == 0) {
            continue;
        }
        Set<String> clss = getClss(pkgn);
        for (String clsn : clss) {
            Class clso = getClso(clsn);
            // 从注解提取动作名
            Action acto = (Action) clso.getAnnotation(Action.class);
            if (acto != null) {
                addActs(acts, acto, clsn, clso);
                continue;
            }
            Cmdlet cmdo = (Cmdlet) clso.getAnnotation(Cmdlet.class);
            if (cmdo != null) {
                addCmds(cmds, cmdo, clsn, clso);
            }
        }
    }
}
Also used : Action(io.github.ihongs.action.anno.Action) Cmdlet(io.github.ihongs.cmdlet.anno.Cmdlet)

Example 17 with Cmdlet

use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.

the class Common method showENV.

@Cmdlet("show-env")
public static void showENV(String[] args) {
    Map<String, String> a = new TreeMap(new PropComparator());
    Map<String, String> m = new HashMap(System.getenv());
    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 18 with Cmdlet

use of io.github.ihongs.cmdlet.anno.Cmdlet in project HongsCORE by ihongs.

the class Common method echo.

@Cmdlet("echo")
public static void echo(String[] args) {
    PrintStream out = CmdletHelper.OUT.get();
    for (String arg : args) {
        out.print(arg);
        out.print(" ");
    }
    out.println();
}
Also used : PrintStream(java.io.PrintStream) 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