Search in sources :

Example 1 with RemoteCommand

use of com.bluenimble.platform.icli.mgm.commands.mgm.RemoteCommand in project serverless by bluenimble.

the class BlueNimble method loadCommands.

private void loadCommands(File commands) {
    if (!commands.exists() || !commands.isDirectory()) {
        commands.mkdir();
        return;
    }
    File[] folders = commands.listFiles(new FileFilter() {

        @Override
        public boolean accept(File f) {
            return f.isDirectory();
        }
    });
    for (File fld : folders) {
        String ctx = fld.getName();
        if (GlobalContext.equals(ctx)) {
            ctx = Tool.ROOT_CTX;
        } else {
            ToolContext toolContext = getContext(ctx);
            if (toolContext == null) {
                addContext(new ToolContextImpl(ctx));
            }
        }
        File[] files = fld.listFiles(new FileFilter() {

            @Override
            public boolean accept(File f) {
                return f.isFile() && f.getName().endsWith(".json");
            }
        });
        String name = null;
        for (File f : files) {
            name = f.getName().substring(0, f.getName().indexOf(JsonExt));
            try {
                addCommand(new RemoteCommand(ctx, name, Json.load(f)));
            } catch (Exception e) {
                System.out.println("ERROR: Can't load command " + name + ". Cause: " + e.getMessage());
            }
        }
    }
}
Also used : RemoteCommand(com.bluenimble.platform.icli.mgm.commands.mgm.RemoteCommand) ToolContextImpl(com.bluenimble.platform.cli.impls.ToolContextImpl) ToolContext(com.bluenimble.platform.cli.ToolContext) FileFilter(java.io.FileFilter) File(java.io.File) InstallI18nException(com.bluenimble.platform.cli.InstallI18nException) ToolStartupException(com.bluenimble.platform.cli.ToolStartupException) IOException(java.io.IOException)

Aggregations

InstallI18nException (com.bluenimble.platform.cli.InstallI18nException)1 ToolContext (com.bluenimble.platform.cli.ToolContext)1 ToolStartupException (com.bluenimble.platform.cli.ToolStartupException)1 ToolContextImpl (com.bluenimble.platform.cli.impls.ToolContextImpl)1 RemoteCommand (com.bluenimble.platform.icli.mgm.commands.mgm.RemoteCommand)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 IOException (java.io.IOException)1