Search in sources :

Example 1 with Console

use of org.eclipse.smarthome.io.console.Console 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)

Example 2 with Console

use of org.eclipse.smarthome.io.console.Console in project smarthome by eclipse.

the class CommandWrapper method execute.

@Override
public Object execute(Session session, List<Object> argList) throws Exception {
    String[] args = argList.stream().map(a -> a.toString()).collect(Collectors.toList()).toArray(new String[0]);
    final Console console = new OSGiConsole(getScope());
    if (args.length == 1 && "--help".equals(args[0])) {
        for (final String usage : command.getUsages()) {
            console.printUsage(usage);
        }
    } else {
        ConsoleInterpreter.execute(console, command, args);
    }
    return null;
}
Also used : Console(org.eclipse.smarthome.io.console.Console)

Aggregations

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