Search in sources :

Example 1 with Alias

use of com.martiansoftware.nailgun.Alias in project nailgun by facebook.

the class NGAlias method nailMain.

public static void nailMain(NGContext context) throws ClassNotFoundException {
    String[] args = context.getArgs();
    NGServer server = context.getNGServer();
    if (args.length == 0) {
        Set aliases = server.getAliasManager().getAliases();
        // let's pad this nicely.  first, find the longest alias
        // name.  then pad the others to that width.
        int maxAliasLength = 0;
        int maxClassnameLength = 0;
        for (Iterator i = aliases.iterator(); i.hasNext(); ) {
            Alias alias = (Alias) i.next();
            maxAliasLength = Math.max(maxAliasLength, alias.getName().length());
            maxClassnameLength = Math.max(maxClassnameLength, alias.getAliasedClass().getName().length());
        }
        for (Iterator i = aliases.iterator(); i.hasNext(); ) {
            Alias alias = (Alias) i.next();
            context.out.println(padl(alias.getName(), maxAliasLength) + "\t" + padl(alias.getAliasedClass().getName(), maxClassnameLength));
            context.out.println(padl("", maxAliasLength) + "\t" + alias.getDescription());
            context.out.println();
        }
    } else if (args.length == 2) {
        server.getAliasManager().addAlias(new Alias(args[0], "", Class.forName(args[1])));
    }
}
Also used : NGServer(com.martiansoftware.nailgun.NGServer) Set(java.util.Set) Alias(com.martiansoftware.nailgun.Alias) Iterator(java.util.Iterator)

Aggregations

Alias (com.martiansoftware.nailgun.Alias)1 NGServer (com.martiansoftware.nailgun.NGServer)1 Iterator (java.util.Iterator)1 Set (java.util.Set)1