Search in sources :

Example 1 with ToolContextImpl

use of com.bluenimble.platform.cli.impls.ToolContextImpl 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)

Example 2 with ToolContextImpl

use of com.bluenimble.platform.cli.impls.ToolContextImpl in project serverless by bluenimble.

the class BlueNimble method loadScripts.

private void loadScripts(File scripts) {
    if (!scripts.exists() || !scripts.isDirectory()) {
        scripts.mkdir();
        return;
    }
    File[] folders = scripts.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(MacroExt) || f.getName().endsWith(ScriptExt));
            }
        });
        String name = null;
        for (File f : files) {
            name = f.getName().substring(0, f.getName().lastIndexOf(Lang.DOT));
            try {
                Command c = null;
                if (f.getName().endsWith(MacroExt)) {
                    c = new MacroSourceCommand(ctx, name, f);
                } else if (f.getName().endsWith(ScriptExt)) {
                    c = new ScriptSourceCommand(ctx, name, f);
                }
                if (c != null) {
                    addCommand(c);
                }
            } catch (Exception e) {
                System.out.println("ERROR: Can't load command " + name + ". Cause: " + e.getMessage());
            }
        }
    }
}
Also used : ScriptSourceCommand(com.bluenimble.platform.icli.mgm.commands.mgm.ScriptSourceCommand) SecureCommand(com.bluenimble.platform.icli.mgm.commands.dev.SecureCommand) FeaturesCommand(com.bluenimble.platform.icli.mgm.commands.dev.FeaturesCommand) KeysCommand(com.bluenimble.platform.icli.mgm.commands.dev.KeysCommand) UseCommand(com.bluenimble.platform.icli.mgm.commands.dev.UseCommand) HttpCommand(com.bluenimble.platform.icli.mgm.commands.dev.HttpCommand) CreateCommand(com.bluenimble.platform.icli.mgm.commands.dev.CreateCommand) MacroSourceCommand(com.bluenimble.platform.icli.mgm.commands.mgm.MacroSourceCommand) ApiCommand(com.bluenimble.platform.icli.mgm.commands.dev.ApiCommand) WorkspaceCommand(com.bluenimble.platform.icli.mgm.commands.dev.WorkspaceCommand) Command(com.bluenimble.platform.cli.command.Command) ScriptSourceCommand(com.bluenimble.platform.icli.mgm.commands.mgm.ScriptSourceCommand) RemoteCommand(com.bluenimble.platform.icli.mgm.commands.mgm.RemoteCommand) LoadCommand(com.bluenimble.platform.icli.mgm.commands.dev.LoadCommand) ToolContextImpl(com.bluenimble.platform.cli.impls.ToolContextImpl) ToolContext(com.bluenimble.platform.cli.ToolContext) MacroSourceCommand(com.bluenimble.platform.icli.mgm.commands.mgm.MacroSourceCommand) 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)2 ToolContext (com.bluenimble.platform.cli.ToolContext)2 ToolStartupException (com.bluenimble.platform.cli.ToolStartupException)2 ToolContextImpl (com.bluenimble.platform.cli.impls.ToolContextImpl)2 RemoteCommand (com.bluenimble.platform.icli.mgm.commands.mgm.RemoteCommand)2 File (java.io.File)2 FileFilter (java.io.FileFilter)2 IOException (java.io.IOException)2 Command (com.bluenimble.platform.cli.command.Command)1 ApiCommand (com.bluenimble.platform.icli.mgm.commands.dev.ApiCommand)1 CreateCommand (com.bluenimble.platform.icli.mgm.commands.dev.CreateCommand)1 FeaturesCommand (com.bluenimble.platform.icli.mgm.commands.dev.FeaturesCommand)1 HttpCommand (com.bluenimble.platform.icli.mgm.commands.dev.HttpCommand)1 KeysCommand (com.bluenimble.platform.icli.mgm.commands.dev.KeysCommand)1 LoadCommand (com.bluenimble.platform.icli.mgm.commands.dev.LoadCommand)1 SecureCommand (com.bluenimble.platform.icli.mgm.commands.dev.SecureCommand)1 UseCommand (com.bluenimble.platform.icli.mgm.commands.dev.UseCommand)1 WorkspaceCommand (com.bluenimble.platform.icli.mgm.commands.dev.WorkspaceCommand)1 MacroSourceCommand (com.bluenimble.platform.icli.mgm.commands.mgm.MacroSourceCommand)1 ScriptSourceCommand (com.bluenimble.platform.icli.mgm.commands.mgm.ScriptSourceCommand)1