Search in sources :

Example 1 with ToolContext

use of com.bluenimble.platform.cli.ToolContext in project serverless by bluenimble.

the class AbstractTool method onCommand.

protected String onCommand(String commandName, String params) {
    ToolContext toolContext = currentContext();
    toolContext.put(ToolContext.CommandName, commandName);
    if (params == null) {
        toolContext.remove(ToolContext.CommandLine);
        return params;
    }
    params = params.trim();
    toolContext.put(ToolContext.CommandLine, params);
    return params;
}
Also used : ToolContext(com.bluenimble.platform.cli.ToolContext)

Example 2 with ToolContext

use of com.bluenimble.platform.cli.ToolContext 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 3 with ToolContext

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

Example 4 with ToolContext

use of com.bluenimble.platform.cli.ToolContext in project serverless by bluenimble.

the class ChangeContextCommand method execute.

@Override
public CommandResult execute(Tool tool, Map<String, CommandOption> options) throws CommandExecutionException {
    CommandOption co = options.get(CommandOption.CMD_LINE);
    if (co == null || co.getArg(0) == null) {
        return new DefaultCommandResult(CommandResult.KO, "Specify a valid context name");
    }
    String contextName = (String) co.getArg(0);
    contextName = contextName.toLowerCase();
    ToolContext ctx = tool.getContext(contextName);
    if (ctx == null) {
        return new DefaultCommandResult(CommandResult.KO, "Context [" + contextName + "] not registered with this tool");
    }
    tool.changeContext(ctx);
    return new DefaultCommandResult(CommandResult.OK, "Context changed to [" + contextName + "]");
}
Also used : CommandOption(com.bluenimble.platform.cli.command.CommandOption) ToolContext(com.bluenimble.platform.cli.ToolContext)

Aggregations

ToolContext (com.bluenimble.platform.cli.ToolContext)4 InstallI18nException (com.bluenimble.platform.cli.InstallI18nException)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 CommandOption (com.bluenimble.platform.cli.command.CommandOption)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