Search in sources :

Example 1 with ConsoleCommandExtension

use of org.eclipse.smarthome.io.console.extensions.ConsoleCommandExtension in project smarthome by eclipse.

the class ConsoleSupportEclipse method _smarthome.

/**
 * Methods staring with "_" will be used as commands. We only define one command "smarthome" to make
 * sure we do not get into conflict with other existing commands. The different functionalities
 * can then be used by the first argument.
 *
 * @param interpreter the equinox command interpreter
 * @return null, return parameter is not used
 */
public Object _smarthome(final CommandInterpreter interpreter) {
    final Console console = new OSGiConsole(BASE, interpreter);
    final String cmd = interpreter.nextArgument();
    if (cmd == null) {
        ConsoleInterpreter.printHelp(console, BASE, " ", getConsoleCommandExtensions());
    } else {
        final ConsoleCommandExtension extension = getConsoleCommandExtension(cmd);
        if (extension == null) {
            console.println(String.format("No handler for command '%s' was found.", cmd));
        } else {
            // Build argument list
            final List<String> argsList = new ArrayList<String>();
            while (true) {
                final String narg = interpreter.nextArgument();
                if (!StringUtils.isEmpty(narg)) {
                    argsList.add(narg);
                } else {
                    break;
                }
            }
            final String[] args = new String[argsList.size()];
            argsList.toArray(args);
            ConsoleInterpreter.execute(console, extension, args);
        }
    }
    return null;
}
Also used : Console(org.eclipse.smarthome.io.console.Console) ArrayList(java.util.ArrayList) ConsoleCommandExtension(org.eclipse.smarthome.io.console.extensions.ConsoleCommandExtension)

Aggregations

ArrayList (java.util.ArrayList)1 Console (org.eclipse.smarthome.io.console.Console)1 ConsoleCommandExtension (org.eclipse.smarthome.io.console.extensions.ConsoleCommandExtension)1