Package henplus

Examples of henplus.Command


        final Iterator<String> it = disp.getRegisteredCommandNames(lastWord);
        return new SortedMatchIterator(lastWord, it) {

            @Override
            protected boolean exclude(final String cmdName) {
                final Command cmd = disp.getCommandFrom(cmdName);
                return cmd.getLongDescription(cmdName) == null;
            }
        };
    }
View Full Code Here


         * nothing given: provide generic help.
         */
        if (param == null) {
            final Iterator<Command> it = HenPlus.getInstance().getDispatcher().getRegisteredCommands();
            while (it.hasNext()) {
                final Command cmd = it.next();
                final String description = cmd.getShortDescription();
                if (description == null) {
                    continue;
                }

                final StringBuilder cmdPrint = new StringBuilder(" ");
                final String[] cmds = cmd.getCommandList();
                final String firstSynopsis = cmd.getSynopsis(cmds[0]);
                /*
                 * either print a list of known commands or the complete
                 * synopsis, if there is only one command.
                 */
                if (cmds.length > 1 || firstSynopsis == null) {
                    for (int i = 0; i < cmds.length; ++i) {
                        if (i != 0) {
                            cmdPrint.append(" | ");
                        }
                        cmdPrint.append(cmds[i]);
                    }
                } else {
                    cmdPrint.append(firstSynopsis.length() < INDENT ? firstSynopsis : cmds[0]);
                }
                HenPlus.msg().print(cmdPrint.toString());
                for (int i = cmdPrint.length(); i < INDENT; ++i) {
                    HenPlus.msg().print(" ");
                }
                HenPlus.msg().print(": ");
                HenPlus.msg().println(description);
            }
            HenPlus.msg().println("Full documentation at http://henplus.sf.net/");
            HenPlus.msg().println("config read from [" + HenPlus.getInstance().getConfigurationDirectoryInfo() + "]");
        } else {
            final CommandDispatcher disp = HenPlus.getInstance().getDispatcher();
            final String cmdString = disp.getCommandNameFrom(param);
            final Command c = disp.getCommandFrom(param);
            if (c == null) {
                HenPlus.msg().println("Help: unknown command '" + param + "'");
                return EXEC_FAILED;
            }
            printDescription(cmdString, c);
View Full Code Here

         * ok, someone tries to complete something that is a command. try to
         * find the actual command and ask that command to do the completion.
         */
        final String toExecute = _aliases.get(cmd);
        if (toExecute != null) {
            final Command c = disp.getCommandFrom(toExecute);
            if (c != null) {
                int i = 0;
                final String param = partialCommand;
                while (param.length() < i && Character.isWhitespace(param.charAt(i))) {
                    ++i;
                }
                while (param.length() < i && !Character.isWhitespace(param.charAt(i))) {
                    ++i;
                }
                return c.complete(disp, toExecute + param.substring(i), lastWord);
            }
        }

        return null;
    }
View Full Code Here

                String actualCmdStr = _aliases.get(cmd);
                if (actualCmdStr != null) {
                    final StringTokenizer st = new StringTokenizer(actualCmdStr);
                    actualCmdStr = st.nextToken();
                    final Command c = _dispatcher.getCommandFrom(actualCmdStr);
                    String longDesc = null;
                    if (c != null && (longDesc = c.getLongDescription(actualCmdStr)) != null) {
                        dsc += "\n\n\t..the following description could be determined for this";
                        dsc += "\n\t------- [" + actualCmdStr + "] ---\n";
                        dsc += longDesc;
                    }
                    _currentExecutedAliases.clear();
View Full Code Here

                while ((line = in.readLine()) != null) {
                    line = line.trim();
                    if (line.length() == 0) {
                        continue;
                    }
                    Command plugin = null;
                    try {
                        plugin = loadPlugin(line);
                    } catch (final Exception e) {
                        HenPlus.msg().println("couldn't load plugin '" + line + "' " + e.getMessage());
                    }
View Full Code Here

    /**
     * load a plugin and register it at HenPlus.
     */
    private Command loadPlugin(final String className) throws ClassNotFoundException, ClassCastException, InstantiationException,
            IllegalAccessException {
        Command plugin = null;
        final Class<?> pluginClass = Class.forName(className);
        plugin = (Command) pluginClass.newInstance();
        _henplus.getDispatcher().register(plugin);
        return plugin;
    }
View Full Code Here

            DRV_META[0].resetWidth();
            DRV_META[1].resetWidth();
            final TableRenderer table = new TableRenderer(DRV_META, HenPlus.out());
            for (Entry<String,Command> entry : _plugins.entrySet()) {
                final Column[] row = new Column[2];
                final Command c = entry.getValue();
                final String clsName = entry.getKey();
                row[0] = new Column((c != null ? "* " : "  ") + clsName);
                if (c != null) {
                    final StringBuilder cmds = new StringBuilder();
                    final String[] cmdList = c.getCommandList();
                    for (int i = 0; i < cmdList.length; ++i) {
                        cmds.append(cmdList[i]).append("\n");
                    }
                    row[1] = new Column(cmds.toString().trim());
                } else {
                    row[1] = new Column(null);
                }
                table.addRow(row);
            }
            table.closeTable();
            return SUCCESS;
        } else if ("plug-in".equals(cmd)) {
            if (argc != 1) {
                return SYNTAX_ERROR;
            }
            final String pluginClass = (String) st.nextElement();
            if (_plugins.containsKey(pluginClass)) {
                HenPlus.msg().println("plugin '" + pluginClass + "' already loaded");
                return EXEC_FAILED;
            }
            Command plugin = null;
            try {
                plugin = loadPlugin(pluginClass);
            } catch (final Exception e) {
                HenPlus.msg().println("couldn't load plugin: " + e.getMessage());
                return EXEC_FAILED;
            }
            if (plugin != null) {
                _plugins.put(pluginClass, plugin);
                final String[] cmds = plugin.getCommandList();
                HenPlus.out().print("adding commands: ");
                for (int i = 0; i < cmds.length; ++i) {
                    if (i != 0) {
                        HenPlus.out().print(", ");
                    }
                    HenPlus.out().print(cmds[i]);
                }
                HenPlus.out().println();
            }
        } else if ("plug-out".equals(cmd)) {
            if (argc != 1) {
                return SYNTAX_ERROR;
            }
            final String pluginClass = (String) st.nextElement();
            if (!_plugins.containsKey(pluginClass)) {
                HenPlus.msg().println("unknown plugin '" + pluginClass + "'");
                return EXEC_FAILED;
            } else {
                final Command c = _plugins.remove(pluginClass);
                _henplus.getDispatcher().unregister(c);
            }
        }
        return SUCCESS;
    }
View Full Code Here

TOP

Related Classes of henplus.Command

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.